473,651 Members | 2,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Grid within a Grid ItemDataBound event problem

Im trying to create a grid within a grid programmaticall y. Ive been
successful in doing this but I need the embedded grid to fire its
ItemDataBound event so I can handle it. The event does not seem to fire for
some reason. The code is below.

Look towards the end of the CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e) method. This is where I register the event and
place the programmaticall y created grid into the main grid. The registered
event does not cause the OrdersDataGrid_ ItemDataBound to run.

Appreciate anyones help.

Thanks,
Girish
------------
ASPX File
-----------

<%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid"
EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs"
AutoEventWireup ="false" %>
<HTML>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<!-- Begin Web Form -->
<form id="CustomerOrd erDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p>
<!-- Begin DataGrid -->
<asp:DataGrid id="CustomerDat aGrid" runat="server"
AutoGenerateCol umns="False" CellPadding="2"
CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
BorderColor="Bl ack" BorderWidth="1"
GridLines="Hori zontal"
OnItemDataBound ="CustomerDataG rid_OnItemDataB ound" EnableViewState ="False">
<AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style>
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
ForeColor="Whit e" BackColor="Maro on"></HeaderStyle>
<Columns>
<asp:BoundColum n Visible="False"
DataField="Cust omerID"></asp:BoundColumn >
<asp:HyperLinkC olumn
DataTextField=" CustomerID"
DataNavigateUrl Field="Customer ID"
DataNavigateUrl FormatString="O rderDetailDataG rid.aspx?custom erid={0}"
HeaderText="ID"
ItemStyle-VerticalAlign=" Top" />

<asp:TemplateCo lumn HeaderText="Cus tomer">
<ItemStyle VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<b>
<%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %>
</b>
<br>
<%# DataBinder.Eval (Container.Data Item, "Address" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "City" ) %>
,
<%# DataBinder.Eval (Container.Data Item, "Region") %>
<%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %>
<br>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "Phone" ) %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn ItemStyle-VerticalAlign=" Top"
HeaderText="Ord ers">
<%-- Embedded DataGrid will go here --%>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>

---------------------
CODE BEHIND
----------------------
using System;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;

namespace MasterDetail
{
public class CustomerOrderDa taGrid : System.Web.UI.P age
{
protected DataGrid CustomerDataGri d;
private DataSet ds = new DataSet();

private void Page_Load(objec t sender, System.EventArg s e)
{
string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM Orders";
string conString =
"server=localho st;database=Nor thwind;uid=sa;p wd=tietronix;";

SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);

sda.Fill(ds);
ds.Tables[0].TableName = "Customers" ;
ds.Tables[1].TableName = "Orders";

CustomerDataGri d.DataSource = ds.Tables["Customers"];
CustomerDataGri d.DataBind();
}

//Use the OnItemDataBound event handler to dynamically add an embedded
DataGrid
protected void CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e)
{
//When each row is created in the DataGrid, eval the ItemType
if(e.Item.ItemT ype == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
//If the ItemType is Item or AlternatingItem ,
//Create a new DataGrid object named OrdersDataGrid
DataGrid OrdersDataGrid = new DataGrid();

//Format the DataGrid to look cool.
OrdersDataGrid. BorderWidth = (Unit)1;
OrdersDataGrid. CellPadding = 4;
OrdersDataGrid. CellSpacing = 0;
OrdersDataGrid. GridLines = GridLines.Horiz ontal;
OrdersDataGrid. BorderColor = Color.FromName( "Black");

OrdersDataGrid. ItemStyle.Font. Name = "Verdana";
OrdersDataGrid. ItemStyle.Font. Size = FontUnit.XSmall ;

OrdersDataGrid. AlternatingItem Style.BackColor =
Color.FromName( "LightGray" );

OrdersDataGrid. ShowHeader = true;
OrdersDataGrid. HeaderStyle.Bac kColor = Color.FromName( "Black");
OrdersDataGrid. HeaderStyle.For eColor = Color.FromName( "White");
OrdersDataGrid. HeaderStyle.Fon t.Bold = true;
OrdersDataGrid. HeaderStyle.Fon t.Size = FontUnit.XSmall ;
//Do not autogenerate columns.
OrdersDataGrid. AutoGenerateCol umns = false;

//Add a series of BoundColumns
//Order ID
BoundColumn bc = new BoundColumn();
//Set the BoundColumn Values
bc.HeaderText = "Order ID";
bc.DataField = "OrderID";
bc.ItemStyle.Wr ap = false;
//Add the BoundColumn to the OrdersDataGrid.
OrdersDataGrid. Columns.Add(bc) ;

//Order Date
bc = new BoundColumn();
bc.HeaderText = "Order Date";
bc.DataField = "OrderDate" ;
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Required Date
bc = new BoundColumn();
bc.HeaderText = "Required Date";
bc.DataField = "RequiredDa te";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Shipped Date
bc = new BoundColumn();
bc.HeaderText = "Shipped Date";
bc.DataField = "ShippedDat e";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//End BoundColumns
TemplateColumn tc = new TemplateColumn( );
tc.HeaderText = "Drop Down Menu";
OrdersDataGrid. Columns.Add(tc) ;
//Get the Authors DataView and filter it for the current ISBN
DataView _orders = ds.Tables["Orders"].DefaultView;
_orders.RowFilt er = "CustomerID ='" + e.Item.Cells[0].Text + "'";

//Bind the DataGrid.
OrdersDataGrid. DataSource = _orders;
OrdersDataGrid. DataBind();

// ADD THE EVENT TO THE EMBEDDED GRID HERE
OrdersDataGrid. ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Orde rsDataGrid_Item DataBound);
//Add the OrdersDataGrid to the BooksDataGrid.
e.Item.Cells[3].Controls.Add(O rdersDataGrid);
}
}

private void OrdersDataGrid_ ItemDataBound(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
//CODE NEVER REACHES HERE.
int i=1;
i=10 + 12;
}

override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
this.CustomerDa taGrid.ItemCrea ted += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It emCreated);
//this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound);
this.Load += new System.EventHan dler(this.Page_ Load);

}

private void CustomerDataGri d_ItemCreated(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
int i=1;
i=10 + 12;
}
}
}
Nov 19 '05 #1
4 4476
You should add the event handler before you execute the
OrdersDataGrid. DataBind() method.

I have 2 samples of a several-levels hierarchical datagrid working on my
website using both the datagrid server control and the HTML Table:
http://www.societopia.net/samples/webform2.aspx
http://www.societopia.net/samples/webform1.aspx
--
http://www.webswapp.com
"Girish" wrote:
Im trying to create a grid within a grid programmaticall y. Ive been
successful in doing this but I need the embedded grid to fire its
ItemDataBound event so I can handle it. The event does not seem to fire for
some reason. The code is below.

Look towards the end of the CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e) method. This is where I register the event and
place the programmaticall y created grid into the main grid. The registered
event does not cause the OrdersDataGrid_ ItemDataBound to run.

Appreciate anyones help.

Thanks,
Girish
------------
ASPX File
-----------

<%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid"
EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs"
AutoEventWireup ="false" %>
<HTML>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<!-- Begin Web Form -->
<form id="CustomerOrd erDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p>
<!-- Begin DataGrid -->
<asp:DataGrid id="CustomerDat aGrid" runat="server"
AutoGenerateCol umns="False" CellPadding="2"
CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
BorderColor="Bl ack" BorderWidth="1"
GridLines="Hori zontal"
OnItemDataBound ="CustomerDataG rid_OnItemDataB ound" EnableViewState ="False">
<AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style>
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
ForeColor="Whit e" BackColor="Maro on"></HeaderStyle>
<Columns>
<asp:BoundColum n Visible="False"
DataField="Cust omerID"></asp:BoundColumn >
<asp:HyperLinkC olumn
DataTextField=" CustomerID"
DataNavigateUrl Field="Customer ID"
DataNavigateUrl FormatString="O rderDetailDataG rid.aspx?custom erid={0}"
HeaderText="ID"
ItemStyle-VerticalAlign=" Top" />

<asp:TemplateCo lumn HeaderText="Cus tomer">
<ItemStyle VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<b>
<%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %>
</b>
<br>
<%# DataBinder.Eval (Container.Data Item, "Address" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "City" ) %>
,
<%# DataBinder.Eval (Container.Data Item, "Region") %>
<%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %>
<br>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "Phone" ) %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn ItemStyle-VerticalAlign=" Top"
HeaderText="Ord ers">
<%-- Embedded DataGrid will go here --%>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>

---------------------
CODE BEHIND
----------------------
using System;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;

namespace MasterDetail
{
public class CustomerOrderDa taGrid : System.Web.UI.P age
{
protected DataGrid CustomerDataGri d;
private DataSet ds = new DataSet();

private void Page_Load(objec t sender, System.EventArg s e)
{
string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM Orders";
string conString =
"server=localho st;database=Nor thwind;uid=sa;p wd=tietronix;";

SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);

sda.Fill(ds);
ds.Tables[0].TableName = "Customers" ;
ds.Tables[1].TableName = "Orders";

CustomerDataGri d.DataSource = ds.Tables["Customers"];
CustomerDataGri d.DataBind();
}

//Use the OnItemDataBound event handler to dynamically add an embedded
DataGrid
protected void CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e)
{
//When each row is created in the DataGrid, eval the ItemType
if(e.Item.ItemT ype == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
//If the ItemType is Item or AlternatingItem ,
//Create a new DataGrid object named OrdersDataGrid
DataGrid OrdersDataGrid = new DataGrid();

//Format the DataGrid to look cool.
OrdersDataGrid. BorderWidth = (Unit)1;
OrdersDataGrid. CellPadding = 4;
OrdersDataGrid. CellSpacing = 0;
OrdersDataGrid. GridLines = GridLines.Horiz ontal;
OrdersDataGrid. BorderColor = Color.FromName( "Black");

OrdersDataGrid. ItemStyle.Font. Name = "Verdana";
OrdersDataGrid. ItemStyle.Font. Size = FontUnit.XSmall ;

OrdersDataGrid. AlternatingItem Style.BackColor =
Color.FromName( "LightGray" );

OrdersDataGrid. ShowHeader = true;
OrdersDataGrid. HeaderStyle.Bac kColor = Color.FromName( "Black");
OrdersDataGrid. HeaderStyle.For eColor = Color.FromName( "White");
OrdersDataGrid. HeaderStyle.Fon t.Bold = true;
OrdersDataGrid. HeaderStyle.Fon t.Size = FontUnit.XSmall ;
//Do not autogenerate columns.
OrdersDataGrid. AutoGenerateCol umns = false;

//Add a series of BoundColumns
//Order ID
BoundColumn bc = new BoundColumn();
//Set the BoundColumn Values
bc.HeaderText = "Order ID";
bc.DataField = "OrderID";
bc.ItemStyle.Wr ap = false;
//Add the BoundColumn to the OrdersDataGrid.
OrdersDataGrid. Columns.Add(bc) ;

//Order Date
bc = new BoundColumn();
bc.HeaderText = "Order Date";
bc.DataField = "OrderDate" ;
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Required Date
bc = new BoundColumn();
bc.HeaderText = "Required Date";
bc.DataField = "RequiredDa te";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Shipped Date
bc = new BoundColumn();
bc.HeaderText = "Shipped Date";
bc.DataField = "ShippedDat e";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//End BoundColumns
TemplateColumn tc = new TemplateColumn( );
tc.HeaderText = "Drop Down Menu";
OrdersDataGrid. Columns.Add(tc) ;
//Get the Authors DataView and filter it for the current ISBN
DataView _orders = ds.Tables["Orders"].DefaultView;
_orders.RowFilt er = "CustomerID ='" + e.Item.Cells[0].Text + "'";

//Bind the DataGrid.
OrdersDataGrid. DataSource = _orders;
OrdersDataGrid. DataBind();

// ADD THE EVENT TO THE EMBEDDED GRID HERE
OrdersDataGrid. ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Orde rsDataGrid_Item DataBound);
//Add the OrdersDataGrid to the BooksDataGrid.
e.Item.Cells[3].Controls.Add(O rdersDataGrid);
}
}

private void OrdersDataGrid_ ItemDataBound(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
//CODE NEVER REACHES HERE.
int i=1;
i=10 + 12;
}

override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
this.CustomerDa taGrid.ItemCrea ted += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It emCreated);
//this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound);
this.Load += new System.EventHan dler(this.Page_ Load);

}

private void CustomerDataGri d_ItemCreated(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
int i=1;
i=10 + 12;
}
}
}

Nov 19 '05 #2
Nice samples Philip
--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
"Phillip Williams" wrote:
You should add the event handler before you execute the
OrdersDataGrid. DataBind() method.

I have 2 samples of a several-levels hierarchical datagrid working on my
website using both the datagrid server control and the HTML Table:
http://www.societopia.net/samples/webform2.aspx
http://www.societopia.net/samples/webform1.aspx
--
http://www.webswapp.com
"Girish" wrote:
Im trying to create a grid within a grid programmaticall y. Ive been
successful in doing this but I need the embedded grid to fire its
ItemDataBound event so I can handle it. The event does not seem to fire for
some reason. The code is below.

Look towards the end of the CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e) method. This is where I register the event and
place the programmaticall y created grid into the main grid. The registered
event does not cause the OrdersDataGrid_ ItemDataBound to run.

Appreciate anyones help.

Thanks,
Girish
------------
ASPX File
-----------

<%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid"
EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs"
AutoEventWireup ="false" %>
<HTML>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<!-- Begin Web Form -->
<form id="CustomerOrd erDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p>
<!-- Begin DataGrid -->
<asp:DataGrid id="CustomerDat aGrid" runat="server"
AutoGenerateCol umns="False" CellPadding="2"
CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
BorderColor="Bl ack" BorderWidth="1"
GridLines="Hori zontal"
OnItemDataBound ="CustomerDataG rid_OnItemDataB ound" EnableViewState ="False">
<AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style>
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
ForeColor="Whit e" BackColor="Maro on"></HeaderStyle>
<Columns>
<asp:BoundColum n Visible="False"
DataField="Cust omerID"></asp:BoundColumn >
<asp:HyperLinkC olumn
DataTextField=" CustomerID"
DataNavigateUrl Field="Customer ID"
DataNavigateUrl FormatString="O rderDetailDataG rid.aspx?custom erid={0}"
HeaderText="ID"
ItemStyle-VerticalAlign=" Top" />

<asp:TemplateCo lumn HeaderText="Cus tomer">
<ItemStyle VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<b>
<%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %>
</b>
<br>
<%# DataBinder.Eval (Container.Data Item, "Address" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "City" ) %>
,
<%# DataBinder.Eval (Container.Data Item, "Region") %>
<%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %>
<br>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "Phone" ) %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn ItemStyle-VerticalAlign=" Top"
HeaderText="Ord ers">
<%-- Embedded DataGrid will go here --%>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>

---------------------
CODE BEHIND
----------------------
using System;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;

namespace MasterDetail
{
public class CustomerOrderDa taGrid : System.Web.UI.P age
{
protected DataGrid CustomerDataGri d;
private DataSet ds = new DataSet();

private void Page_Load(objec t sender, System.EventArg s e)
{
string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM Orders";
string conString =
"server=localho st;database=Nor thwind;uid=sa;p wd=tietronix;";

SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);

sda.Fill(ds);
ds.Tables[0].TableName = "Customers" ;
ds.Tables[1].TableName = "Orders";

CustomerDataGri d.DataSource = ds.Tables["Customers"];
CustomerDataGri d.DataBind();
}

//Use the OnItemDataBound event handler to dynamically add an embedded
DataGrid
protected void CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e)
{
//When each row is created in the DataGrid, eval the ItemType
if(e.Item.ItemT ype == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
//If the ItemType is Item or AlternatingItem ,
//Create a new DataGrid object named OrdersDataGrid
DataGrid OrdersDataGrid = new DataGrid();

//Format the DataGrid to look cool.
OrdersDataGrid. BorderWidth = (Unit)1;
OrdersDataGrid. CellPadding = 4;
OrdersDataGrid. CellSpacing = 0;
OrdersDataGrid. GridLines = GridLines.Horiz ontal;
OrdersDataGrid. BorderColor = Color.FromName( "Black");

OrdersDataGrid. ItemStyle.Font. Name = "Verdana";
OrdersDataGrid. ItemStyle.Font. Size = FontUnit.XSmall ;

OrdersDataGrid. AlternatingItem Style.BackColor =
Color.FromName( "LightGray" );

OrdersDataGrid. ShowHeader = true;
OrdersDataGrid. HeaderStyle.Bac kColor = Color.FromName( "Black");
OrdersDataGrid. HeaderStyle.For eColor = Color.FromName( "White");
OrdersDataGrid. HeaderStyle.Fon t.Bold = true;
OrdersDataGrid. HeaderStyle.Fon t.Size = FontUnit.XSmall ;
//Do not autogenerate columns.
OrdersDataGrid. AutoGenerateCol umns = false;

//Add a series of BoundColumns
//Order ID
BoundColumn bc = new BoundColumn();
//Set the BoundColumn Values
bc.HeaderText = "Order ID";
bc.DataField = "OrderID";
bc.ItemStyle.Wr ap = false;
//Add the BoundColumn to the OrdersDataGrid.
OrdersDataGrid. Columns.Add(bc) ;

//Order Date
bc = new BoundColumn();
bc.HeaderText = "Order Date";
bc.DataField = "OrderDate" ;
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Required Date
bc = new BoundColumn();
bc.HeaderText = "Required Date";
bc.DataField = "RequiredDa te";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Shipped Date
bc = new BoundColumn();
bc.HeaderText = "Shipped Date";
bc.DataField = "ShippedDat e";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//End BoundColumns
TemplateColumn tc = new TemplateColumn( );
tc.HeaderText = "Drop Down Menu";
OrdersDataGrid. Columns.Add(tc) ;
//Get the Authors DataView and filter it for the current ISBN
DataView _orders = ds.Tables["Orders"].DefaultView;
_orders.RowFilt er = "CustomerID ='" + e.Item.Cells[0].Text + "'";

//Bind the DataGrid.
OrdersDataGrid. DataSource = _orders;
OrdersDataGrid. DataBind();

// ADD THE EVENT TO THE EMBEDDED GRID HERE
OrdersDataGrid. ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Orde rsDataGrid_Item DataBound);
//Add the OrdersDataGrid to the BooksDataGrid.
e.Item.Cells[3].Controls.Add(O rdersDataGrid);
}
}

private void OrdersDataGrid_ ItemDataBound(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
//CODE NEVER REACHES HERE.
int i=1;
i=10 + 12;
}

override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
this.CustomerDa taGrid.ItemCrea ted += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It emCreated);
//this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound);
this.Load += new System.EventHan dler(this.Page_ Load);

}

private void CustomerDataGri d_ItemCreated(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
int i=1;
i=10 + 12;
}
}
}

Nov 19 '05 #3
Thanks Phillip. This helps.

Girish

"Phillip Williams" <Ph************ **@webswapp.com > wrote in message
news:C6******** *************** ***********@mic rosoft.com...
You should add the event handler before you execute the
OrdersDataGrid. DataBind() method.

I have 2 samples of a several-levels hierarchical datagrid working on my
website using both the datagrid server control and the HTML Table:
http://www.societopia.net/samples/webform2.aspx
http://www.societopia.net/samples/webform1.aspx
--
http://www.webswapp.com
"Girish" wrote:
Im trying to create a grid within a grid programmaticall y. Ive been
successful in doing this but I need the embedded grid to fire its
ItemDataBound event so I can handle it. The event does not seem to fire
for
some reason. The code is below.

Look towards the end of the CustomerDataGri d_OnItemDataBou nd(object
sender,
DataGridItemEve ntArgs e) method. This is where I register the event and
place the programmaticall y created grid into the main grid. The
registered
event does not cause the OrdersDataGrid_ ItemDataBound to run.

Appreciate anyones help.

Thanks,
Girish
> ------------
> ASPX File
> -----------

<%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid"
EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs"
AutoEventWireup ="false" %>
<HTML>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<!-- Begin Web Form -->
<form id="CustomerOrd erDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p>
<!-- Begin DataGrid -->
<asp:DataGrid id="CustomerDat aGrid" runat="server"
AutoGenerateCol umns="False" CellPadding="2"
CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
BorderColor="Bl ack" BorderWidth="1"
GridLines="Hori zontal"
OnItemDataBound ="CustomerDataG rid_OnItemDataB ound"
EnableViewState ="False">
<AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style>
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
ForeColor="Whit e" BackColor="Maro on"></HeaderStyle>
<Columns>
<asp:BoundColum n Visible="False"
DataField="Cust omerID"></asp:BoundColumn >
<asp:HyperLinkC olumn
DataTextField=" CustomerID"
DataNavigateUrl Field="Customer ID"

DataNavigateUrl FormatString="O rderDetailDataG rid.aspx?custom erid={0}"
HeaderText="ID"
ItemStyle-VerticalAlign=" Top" />

<asp:TemplateCo lumn HeaderText="Cus tomer">
<ItemStyle VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<b>
<%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %>
</b>
<br>
<%# DataBinder.Eval (Container.Data Item, "Address" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "City" ) %>
,
<%# DataBinder.Eval (Container.Data Item, "Region") %>
<%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %>
<br>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "Phone" ) %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn ItemStyle-VerticalAlign=" Top"
HeaderText="Ord ers">
<%-- Embedded DataGrid will go here --%>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>

---------------------
CODE BEHIND
----------------------
using System;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;

namespace MasterDetail
{
public class CustomerOrderDa taGrid : System.Web.UI.P age
{
protected DataGrid CustomerDataGri d;
private DataSet ds = new DataSet();

private void Page_Load(objec t sender, System.EventArg s e)
{
string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM
Orders";
string conString =
"server=localho st;database=Nor thwind;uid=sa;p wd=tietronix;";

SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);

sda.Fill(ds);
ds.Tables[0].TableName = "Customers" ;
ds.Tables[1].TableName = "Orders";

CustomerDataGri d.DataSource = ds.Tables["Customers"];
CustomerDataGri d.DataBind();
}

//Use the OnItemDataBound event handler to dynamically add an embedded
DataGrid
protected void CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e)
{
//When each row is created in the DataGrid, eval the ItemType
if(e.Item.ItemT ype == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
//If the ItemType is Item or AlternatingItem ,
//Create a new DataGrid object named OrdersDataGrid
DataGrid OrdersDataGrid = new DataGrid();

//Format the DataGrid to look cool.
OrdersDataGrid. BorderWidth = (Unit)1;
OrdersDataGrid. CellPadding = 4;
OrdersDataGrid. CellSpacing = 0;
OrdersDataGrid. GridLines = GridLines.Horiz ontal;
OrdersDataGrid. BorderColor = Color.FromName( "Black");

OrdersDataGrid. ItemStyle.Font. Name = "Verdana";
OrdersDataGrid. ItemStyle.Font. Size = FontUnit.XSmall ;

OrdersDataGrid. AlternatingItem Style.BackColor =
Color.FromName( "LightGray" );

OrdersDataGrid. ShowHeader = true;
OrdersDataGrid. HeaderStyle.Bac kColor = Color.FromName( "Black");
OrdersDataGrid. HeaderStyle.For eColor = Color.FromName( "White");
OrdersDataGrid. HeaderStyle.Fon t.Bold = true;
OrdersDataGrid. HeaderStyle.Fon t.Size = FontUnit.XSmall ;
//Do not autogenerate columns.
OrdersDataGrid. AutoGenerateCol umns = false;

//Add a series of BoundColumns
//Order ID
BoundColumn bc = new BoundColumn();
//Set the BoundColumn Values
bc.HeaderText = "Order ID";
bc.DataField = "OrderID";
bc.ItemStyle.Wr ap = false;
//Add the BoundColumn to the OrdersDataGrid.
OrdersDataGrid. Columns.Add(bc) ;

//Order Date
bc = new BoundColumn();
bc.HeaderText = "Order Date";
bc.DataField = "OrderDate" ;
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Required Date
bc = new BoundColumn();
bc.HeaderText = "Required Date";
bc.DataField = "RequiredDa te";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Shipped Date
bc = new BoundColumn();
bc.HeaderText = "Shipped Date";
bc.DataField = "ShippedDat e";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//End BoundColumns
TemplateColumn tc = new TemplateColumn( );
tc.HeaderText = "Drop Down Menu";
OrdersDataGrid. Columns.Add(tc) ;
//Get the Authors DataView and filter it for the current ISBN
DataView _orders = ds.Tables["Orders"].DefaultView;
_orders.RowFilt er = "CustomerID ='" + e.Item.Cells[0].Text + "'";

//Bind the DataGrid.
OrdersDataGrid. DataSource = _orders;
OrdersDataGrid. DataBind();

// ADD THE EVENT TO THE EMBEDDED GRID HERE
OrdersDataGrid. ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Orde rsDataGrid_Item DataBound);
//Add the OrdersDataGrid to the BooksDataGrid.
e.Item.Cells[3].Controls.Add(O rdersDataGrid);
}
}

private void OrdersDataGrid_ ItemDataBound(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
//CODE NEVER REACHES HERE.
int i=1;
i=10 + 12;
}

override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
this.CustomerDa taGrid.ItemCrea ted += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It emCreated);
//this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound);
this.Load += new System.EventHan dler(this.Page_ Load);

}

private void CustomerDataGri d_ItemCreated(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
int i=1;
i=10 + 12;
}
}
}

Nov 19 '05 #4
Good one Phillips!

"Phillip Williams" <Ph************ **@webswapp.com > wrote in message
news:C6******** *************** ***********@mic rosoft.com...
You should add the event handler before you execute the
OrdersDataGrid. DataBind() method.

I have 2 samples of a several-levels hierarchical datagrid working on my
website using both the datagrid server control and the HTML Table:
http://www.societopia.net/samples/webform2.aspx
http://www.societopia.net/samples/webform1.aspx
--
http://www.webswapp.com
"Girish" wrote:
Im trying to create a grid within a grid programmaticall y. Ive been
successful in doing this but I need the embedded grid to fire its
ItemDataBound event so I can handle it. The event does not seem to fire for some reason. The code is below.

Look towards the end of the CustomerDataGri d_OnItemDataBou nd(object sender, DataGridItemEve ntArgs e) method. This is where I register the event and
place the programmaticall y created grid into the main grid. The registered event does not cause the OrdersDataGrid_ ItemDataBound to run.

Appreciate anyones help.

Thanks,
Girish
------------
ASPX File
-----------

<%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid"
EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs"
AutoEventWireup ="false" %>
<HTML>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<!-- Begin Web Form -->
<form id="CustomerOrd erDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p>
<!-- Begin DataGrid -->
<asp:DataGrid id="CustomerDat aGrid" runat="server"
AutoGenerateCol umns="False" CellPadding="2"
CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
BorderColor="Bl ack" BorderWidth="1"
GridLines="Hori zontal"
OnItemDataBound ="CustomerDataG rid_OnItemDataB ound" EnableViewState ="False"> <AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style>
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
ForeColor="Whit e" BackColor="Maro on"></HeaderStyle>
<Columns>
<asp:BoundColum n Visible="False"
DataField="Cust omerID"></asp:BoundColumn >
<asp:HyperLinkC olumn
DataTextField=" CustomerID"
DataNavigateUrl Field="Customer ID"
DataNavigateUrl FormatString="O rderDetailDataG rid.aspx?custom erid={0}" HeaderText="ID"
ItemStyle-VerticalAlign=" Top" />

<asp:TemplateCo lumn HeaderText="Cus tomer">
<ItemStyle VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<b>
<%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %>
</b>
<br>
<%# DataBinder.Eval (Container.Data Item, "Address" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "City" ) %>
,
<%# DataBinder.Eval (Container.Data Item, "Region") %>
<%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %>
<br>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "Phone" ) %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn ItemStyle-VerticalAlign=" Top"
HeaderText="Ord ers">
<%-- Embedded DataGrid will go here --%>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>

---------------------
CODE BEHIND
----------------------
using System;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;

namespace MasterDetail
{
public class CustomerOrderDa taGrid : System.Web.UI.P age
{
protected DataGrid CustomerDataGri d;
private DataSet ds = new DataSet();

private void Page_Load(objec t sender, System.EventArg s e)
{
string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM Orders"; string conString =
"server=localho st;database=Nor thwind;uid=sa;p wd=tietronix;";

SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);

sda.Fill(ds);
ds.Tables[0].TableName = "Customers" ;
ds.Tables[1].TableName = "Orders";

CustomerDataGri d.DataSource = ds.Tables["Customers"];
CustomerDataGri d.DataBind();
}

//Use the OnItemDataBound event handler to dynamically add an embedded
DataGrid
protected void CustomerDataGri d_OnItemDataBou nd(object sender,
DataGridItemEve ntArgs e)
{
//When each row is created in the DataGrid, eval the ItemType
if(e.Item.ItemT ype == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
//If the ItemType is Item or AlternatingItem ,
//Create a new DataGrid object named OrdersDataGrid
DataGrid OrdersDataGrid = new DataGrid();

//Format the DataGrid to look cool.
OrdersDataGrid. BorderWidth = (Unit)1;
OrdersDataGrid. CellPadding = 4;
OrdersDataGrid. CellSpacing = 0;
OrdersDataGrid. GridLines = GridLines.Horiz ontal;
OrdersDataGrid. BorderColor = Color.FromName( "Black");

OrdersDataGrid. ItemStyle.Font. Name = "Verdana";
OrdersDataGrid. ItemStyle.Font. Size = FontUnit.XSmall ;

OrdersDataGrid. AlternatingItem Style.BackColor =
Color.FromName( "LightGray" );

OrdersDataGrid. ShowHeader = true;
OrdersDataGrid. HeaderStyle.Bac kColor = Color.FromName( "Black");
OrdersDataGrid. HeaderStyle.For eColor = Color.FromName( "White");
OrdersDataGrid. HeaderStyle.Fon t.Bold = true;
OrdersDataGrid. HeaderStyle.Fon t.Size = FontUnit.XSmall ;
//Do not autogenerate columns.
OrdersDataGrid. AutoGenerateCol umns = false;

//Add a series of BoundColumns
//Order ID
BoundColumn bc = new BoundColumn();
//Set the BoundColumn Values
bc.HeaderText = "Order ID";
bc.DataField = "OrderID";
bc.ItemStyle.Wr ap = false;
//Add the BoundColumn to the OrdersDataGrid.
OrdersDataGrid. Columns.Add(bc) ;

//Order Date
bc = new BoundColumn();
bc.HeaderText = "Order Date";
bc.DataField = "OrderDate" ;
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Required Date
bc = new BoundColumn();
bc.HeaderText = "Required Date";
bc.DataField = "RequiredDa te";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//Shipped Date
bc = new BoundColumn();
bc.HeaderText = "Shipped Date";
bc.DataField = "ShippedDat e";
bc.DataFormatSt ring="{0:d}";
bc.ItemStyle.Wr ap = false;
OrdersDataGrid. Columns.Add(bc) ;

//End BoundColumns
TemplateColumn tc = new TemplateColumn( );
tc.HeaderText = "Drop Down Menu";
OrdersDataGrid. Columns.Add(tc) ;
//Get the Authors DataView and filter it for the current ISBN
DataView _orders = ds.Tables["Orders"].DefaultView;
_orders.RowFilt er = "CustomerID ='" + e.Item.Cells[0].Text + "'";

//Bind the DataGrid.
OrdersDataGrid. DataSource = _orders;
OrdersDataGrid. DataBind();

// ADD THE EVENT TO THE EMBEDDED GRID HERE
OrdersDataGrid. ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Orde rsDataGrid_Item D
ataBound); //Add the OrdersDataGrid to the BooksDataGrid.
e.Item.Cells[3].Controls.Add(O rdersDataGrid);
}
}

private void OrdersDataGrid_ ItemDataBound(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
//CODE NEVER REACHES HERE.
int i=1;
i=10 + 12;
}

override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

private void InitializeCompo nent()
{
this.CustomerDa taGrid.ItemCrea ted += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It e
mCreated); //this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On I
temDataBound); this.Load += new System.EventHan dler(this.Page_ Load);

}

private void CustomerDataGri d_ItemCreated(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
int i=1;
i=10 + 12;
}
}
}

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1073
by: poi | last post by:
I define controls completely in code in a PrepControls() method. I put the method in here: #region Web Form Designer generated code override protected void OnInit(EventArgs e) { PrepDynamicControls(); // // CODEGEN: This call is required by the ASP.NET Web Form Designer. //
3
24635
by: MattB | last post by:
I swear I've made this work no problem before and I'm not sure what's gone wrong. I have a form with a datagrid that I'm binding to a DatTable I generate on the fly. If I just bind and load the page I can see all my data fine. Now I want to add a textbox for each row and pre-populate that box with values from my DataTable. So I created a OnItemDataBound event and it's firing. My problem is that any time I try to reference data in the...
1
1561
by: Roy | last post by:
Hey all, This is a fairly broad question, but why is it that my datagrid hits the ItemDataBound event 3 times? Basically, I placed a response.write in all sub and functions in my codebehind and discovered that my page_load,prerender,and binddata subs all get called once, but my itemdatabound event gets called 3 times. What's weird is that there is only 1 row being pushed into the datagrid, so I should only be seeing one itemdatabound...
1
2562
by: needin4mation | last post by:
Hi, I have a datalist. In this datalist I have a datagrid. The datalist is the master. The datagrid is the detail. It works fine. I populate the datagrid inside of the datalist using the datalist's itemdatabound event. Now I need to do some work in the itemdatabound event of the datagrid that is nested. I can't seem to reference it. How can I reference it so that they page knows to look for that event? How can I get to the...
1
2659
by: greenb | last post by:
I'm using the ItemDataBound event of the DataGrid to highlight cells that are outside an acceptable range. Each row has a button column (CommandName='Select'), that is used to display addtional details below the grid. When the page first loads and when the 1st button column is clicked, the ItemDataBound event fires for each row in the datasource. But when the 2nd button column is clicked, the ItemDataBound event does not fire for the...
1
5741
by: teddysnips | last post by:
I come from a VB background and I'm on my first C# project. I have a panel with a DataGridView control. When the program is first run, the panel is instantiated with 4,000 empty rows (this is a business requirement. Trust me.) At some time in the life of the program the user will attempt to load some data into the grid from a file. The grid will be populated by this line:
2
2885
by: Nathan Sokalski | last post by:
I have a DataList control that I use the ItemDataBound event for. One of the properties of the DataList that I use in this event is Me.datMain.Items.Count (datMain is the id of my DataList) in order to determine whether the current DataListItem is the last one. However, the Me.datMain.Items.Count property changes with each calling of the ItemDataBound event (for the first item it is 0, for the second it is 1, for the third it is 2, etc.)....
1
1243
by: Nathan Sokalski | last post by:
I am trying to access the DataItem of other DataListItems in a DataList of mine from within the ItemDataBound. The code I am currently using is: CStr(CType(Me.datMain.Items(e.Item.ItemIndex - 1).DataItem, DataRowView).Row("id")) However, this gives me an error stating that the object cannot be found. What am I doing wrong? Thanks. -- Nathan Sokalski
1
4603
by: Nathan Sokalski | last post by:
I am trying to set the CommandArgument property of a Button control from a template in a DataList of mine using code in the ItemDataBound event. However, it does not want to set the property (it is acting as if I did not set it). Here is my code that sets the CommandArgument property in the ItemDataBound event: CType(e.Item.FindControl("btnMainMoveDown"), Button).CommandArgument = CStr(CType(Me.datMain.DataSource,...
0
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8803
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7298
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.