Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Grid within a Grid ItemDataBound event problem

Reply
Thread Tools

Grid within a Grid ItemDataBound event problem

 
 
Girish
Guest
Posts: n/a
 
      07-18-2005
Im trying to create a grid within a grid programmatically. 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 CustomerDataGrid_OnItemDataBound(object sender,
DataGridItemEventArgs e) method. This is where I register the event and
place the programmatically 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="MasterDetail.CustomerOrderDataGrid"
EnableViewState="False" CodeBehind="CustomerOrderDataGrid.aspx.cs"
AutoEventWireup="false" %>
<HTML>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<!-- Begin Web Form -->
<form id="CustomerOrderDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p>
<!-- Begin DataGrid -->
<aspataGrid id="CustomerDataGrid" runat="server"
AutoGenerateColumns="False" CellPadding="2"
CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
BorderColor="Black" BorderWidth="1"
GridLines="Horizontal"
OnItemDataBound="CustomerDataGrid_OnItemDataBound" EnableViewState="False">
<AlternatingItemStyle BackColor="Tan"></AlternatingItemStyle>
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
ForeColor="White" BackColor="Maroon"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False"
DataField="CustomerID"></asp:BoundColumn>
<asp:HyperLinkColumn
DataTextField="CustomerID"
DataNavigateUrlField="CustomerID"
DataNavigateUrlFormatString="OrderDetailDataGrid.a spx?customerid={0}"
HeaderText="ID"
ItemStyle-VerticalAlign="Top" />

<asp:TemplateColumn HeaderText="Customer">
<ItemStyle VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<b>
<%# DataBinder.Eval(Container.DataItem, "CompanyName") %>
</b>
<br>
<%# DataBinder.Eval(Container.DataItem, "Address" ) %>
<br>
<%# DataBinder.Eval(Container.DataItem, "City" ) %>
,
<%# DataBinder.Eval(Container.DataItem, "Region") %>
<%# DataBinder.Eval(Container.DataItem, "PostalCode" ) %>
<br>
<br>
<%# DataBinder.Eval(Container.DataItem, "ContactName" ) %>
<br>
<%# DataBinder.Eval(Container.DataItem, "ContactTitle" ) %>
<br>
<%# DataBinder.Eval(Container.DataItem, "Phone" ) %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn ItemStyle-VerticalAlign="Top"
HeaderText="Orders">
<%-- Embedded DataGrid will go here --%>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>

---------------------
CODE BEHIND
----------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;

namespace MasterDetail
{
public class CustomerOrderDataGrid : System.Web.UI.Page
{
protected DataGrid CustomerDataGrid;
private DataSet ds = new DataSet();

private void Page_Load(object sender, System.EventArgs e)
{
string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM Orders";
string conString =
"server=localhost;database=Northwind;uid=sa;pwd=ti etronix;";

SqlDataAdapter sda = new SqlDataAdapter(sqlStmt, conString);

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

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

//Use the OnItemDataBound event handler to dynamically add an embedded
DataGrid
protected void CustomerDataGrid_OnItemDataBound(object sender,
DataGridItemEventArgs e)
{
//When each row is created in the DataGrid, eval the ItemType
if(e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
//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.Horizontal;
OrdersDataGrid.BorderColor = Color.FromName("Black");

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

OrdersDataGrid.AlternatingItemStyle.BackColor =
Color.FromName("LightGray");

OrdersDataGrid.ShowHeader = true;
OrdersDataGrid.HeaderStyle.BackColor = Color.FromName("Black");
OrdersDataGrid.HeaderStyle.ForeColor = Color.FromName("White");
OrdersDataGrid.HeaderStyle.Font.Bold = true;
OrdersDataGrid.HeaderStyle.Font.Size = FontUnit.XSmall;


//Do not autogenerate columns.
OrdersDataGrid.AutoGenerateColumns = 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.Wrap = false;
//Add the BoundColumn to the OrdersDataGrid.
OrdersDataGrid.Columns.Add(bc);

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

//Required Date
bc = new BoundColumn();
bc.HeaderText = "Required Date";
bc.DataField = "RequiredDate";
bc.DataFormatString="{0:d}";
bc.ItemStyle.Wrap = false;
OrdersDataGrid.Columns.Add(bc);

//Shipped Date
bc = new BoundColumn();
bc.HeaderText = "Shipped Date";
bc.DataField = "ShippedDate";
bc.DataFormatString="{0:d}";
bc.ItemStyle.Wrap = 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.RowFilter = "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.WebControls.DataGridItemEventHandler (this.OrdersDataGrid_ItemDataBound);
//Add the OrdersDataGrid to the BooksDataGrid.
e.Item.Cells[3].Controls.Add(OrdersDataGrid);
}
}

private void OrdersDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//CODE NEVER REACHES HERE.
int i=1;
i=10 + 12;
}

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

private void InitializeComponent()
{
this.CustomerDataGrid.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_ItemCreated);
//this.CustomerDataGrid.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_OnItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);

}

private void CustomerDataGrid_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int i=1;
i=10 + 12;
}
}
}


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      07-18-2005
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 programmatically. 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 CustomerDataGrid_OnItemDataBound(object sender,
> DataGridItemEventArgs e) method. This is where I register the event and
> place the programmatically 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="MasterDetail.CustomerOrderDataGrid"
> EnableViewState="False" CodeBehind="CustomerOrderDataGrid.aspx.cs"
> AutoEventWireup="false" %>
> <HTML>
> <body style="FONT: x-small Verdana, Arial, sans-serif">
> <!-- Begin Web Form -->
> <form id="CustomerOrderDataGrid" method="post" runat="server">
> <p><a href="/DayOfDotNet/">Parent Directory</a></p>
> <!-- Begin DataGrid -->
> <aspataGrid id="CustomerDataGrid" runat="server"
> AutoGenerateColumns="False" CellPadding="2"
> CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
> BorderColor="Black" BorderWidth="1"
> GridLines="Horizontal"
> OnItemDataBound="CustomerDataGrid_OnItemDataBound" EnableViewState="False">
> <AlternatingItemStyle BackColor="Tan"></AlternatingItemStyle>
> <ItemStyle Font-Size="X-Small"></ItemStyle>
> <HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
> ForeColor="White" BackColor="Maroon"></HeaderStyle>
> <Columns>
> <asp:BoundColumn Visible="False"
> DataField="CustomerID"></asp:BoundColumn>
> <asp:HyperLinkColumn
> DataTextField="CustomerID"
> DataNavigateUrlField="CustomerID"
> DataNavigateUrlFormatString="OrderDetailDataGrid.a spx?customerid={0}"
> HeaderText="ID"
> ItemStyle-VerticalAlign="Top" />
>
> <asp:TemplateColumn HeaderText="Customer">
> <ItemStyle VerticalAlign="Top"></ItemStyle>
> <ItemTemplate>
> <b>
> <%# DataBinder.Eval(Container.DataItem, "CompanyName") %>
> </b>
> <br>
> <%# DataBinder.Eval(Container.DataItem, "Address" ) %>
> <br>
> <%# DataBinder.Eval(Container.DataItem, "City" ) %>
> ,
> <%# DataBinder.Eval(Container.DataItem, "Region") %>
> <%# DataBinder.Eval(Container.DataItem, "PostalCode" ) %>
> <br>
> <br>
> <%# DataBinder.Eval(Container.DataItem, "ContactName" ) %>
> <br>
> <%# DataBinder.Eval(Container.DataItem, "ContactTitle" ) %>
> <br>
> <%# DataBinder.Eval(Container.DataItem, "Phone" ) %>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn ItemStyle-VerticalAlign="Top"
> HeaderText="Orders">
> <%-- Embedded DataGrid will go here --%>
> </asp:TemplateColumn>
> </Columns>
> </aspataGrid>
> <!-- End DataGrid -->
> </form>
> <!-- End Web Form -->
> </body>
> </HTML>
>
> ---------------------
> CODE BEHIND
> ----------------------
> using System;
> using System.Data;
> using System.Data.SqlClient;
> using System.Drawing;
> using System.Web;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.HtmlControls;
> using System.Configuration;
>
> namespace MasterDetail
> {
> public class CustomerOrderDataGrid : System.Web.UI.Page
> {
> protected DataGrid CustomerDataGrid;
> private DataSet ds = new DataSet();
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM Orders";
> string conString =
> "server=localhost;database=Northwind;uid=sa;pwd=ti etronix;";
>
> SqlDataAdapter sda = new SqlDataAdapter(sqlStmt, conString);
>
> sda.Fill(ds);
> ds.Tables[0].TableName = "Customers";
> ds.Tables[1].TableName = "Orders";
>
> CustomerDataGrid.DataSource = ds.Tables["Customers"];
> CustomerDataGrid.DataBind();
> }
>
> //Use the OnItemDataBound event handler to dynamically add an embedded
> DataGrid
> protected void CustomerDataGrid_OnItemDataBound(object sender,
> DataGridItemEventArgs e)
> {
> //When each row is created in the DataGrid, eval the ItemType
> if(e.Item.ItemType == ListItemType.Item ||
> e.Item.ItemType == ListItemType.AlternatingItem)
> {
> //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.Horizontal;
> OrdersDataGrid.BorderColor = Color.FromName("Black");
>
> OrdersDataGrid.ItemStyle.Font.Name = "Verdana";
> OrdersDataGrid.ItemStyle.Font.Size = FontUnit.XSmall;
>
> OrdersDataGrid.AlternatingItemStyle.BackColor =
> Color.FromName("LightGray");
>
> OrdersDataGrid.ShowHeader = true;
> OrdersDataGrid.HeaderStyle.BackColor = Color.FromName("Black");
> OrdersDataGrid.HeaderStyle.ForeColor = Color.FromName("White");
> OrdersDataGrid.HeaderStyle.Font.Bold = true;
> OrdersDataGrid.HeaderStyle.Font.Size = FontUnit.XSmall;
>
>
> //Do not autogenerate columns.
> OrdersDataGrid.AutoGenerateColumns = 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.Wrap = false;
> //Add the BoundColumn to the OrdersDataGrid.
> OrdersDataGrid.Columns.Add(bc);
>
> //Order Date
> bc = new BoundColumn();
> bc.HeaderText = "Order Date";
> bc.DataField = "OrderDate";
> bc.DataFormatString="{0:d}";
> bc.ItemStyle.Wrap = false;
> OrdersDataGrid.Columns.Add(bc);
>
> //Required Date
> bc = new BoundColumn();
> bc.HeaderText = "Required Date";
> bc.DataField = "RequiredDate";
> bc.DataFormatString="{0:d}";
> bc.ItemStyle.Wrap = false;
> OrdersDataGrid.Columns.Add(bc);
>
> //Shipped Date
> bc = new BoundColumn();
> bc.HeaderText = "Shipped Date";
> bc.DataField = "ShippedDate";
> bc.DataFormatString="{0:d}";
> bc.ItemStyle.Wrap = 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.RowFilter = "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.WebControls.DataGridItemEventHandler (this.OrdersDataGrid_ItemDataBound);
> //Add the OrdersDataGrid to the BooksDataGrid.
> e.Item.Cells[3].Controls.Add(OrdersDataGrid);
> }
> }
>
> private void OrdersDataGrid_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> //CODE NEVER REACHES HERE.
> int i=1;
> i=10 + 12;
> }
>
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> private void InitializeComponent()
> {
> this.CustomerDataGrid.ItemCreated += new
> System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_ItemCreated);
> //this.CustomerDataGrid.ItemDataBound += new
> System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_OnItemDataBound);
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
>
> private void CustomerDataGrid_ItemCreated(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> int i=1;
> i=10 + 12;
> }
> }
> }
>
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?dmluYXk=?=
Guest
Posts: n/a
 
      07-18-2005
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 programmatically. 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 CustomerDataGrid_OnItemDataBound(object sender,
> > DataGridItemEventArgs e) method. This is where I register the event and
> > place the programmatically 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="MasterDetail.CustomerOrderDataGrid"
> > EnableViewState="False" CodeBehind="CustomerOrderDataGrid.aspx.cs"
> > AutoEventWireup="false" %>
> > <HTML>
> > <body style="FONT: x-small Verdana, Arial, sans-serif">
> > <!-- Begin Web Form -->
> > <form id="CustomerOrderDataGrid" method="post" runat="server">
> > <p><a href="/DayOfDotNet/">Parent Directory</a></p>
> > <!-- Begin DataGrid -->
> > <aspataGrid id="CustomerDataGrid" runat="server"
> > AutoGenerateColumns="False" CellPadding="2"
> > CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
> > BorderColor="Black" BorderWidth="1"
> > GridLines="Horizontal"
> > OnItemDataBound="CustomerDataGrid_OnItemDataBound" EnableViewState="False">
> > <AlternatingItemStyle BackColor="Tan"></AlternatingItemStyle>
> > <ItemStyle Font-Size="X-Small"></ItemStyle>
> > <HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
> > ForeColor="White" BackColor="Maroon"></HeaderStyle>
> > <Columns>
> > <asp:BoundColumn Visible="False"
> > DataField="CustomerID"></asp:BoundColumn>
> > <asp:HyperLinkColumn
> > DataTextField="CustomerID"
> > DataNavigateUrlField="CustomerID"
> > DataNavigateUrlFormatString="OrderDetailDataGrid.a spx?customerid={0}"
> > HeaderText="ID"
> > ItemStyle-VerticalAlign="Top" />
> >
> > <asp:TemplateColumn HeaderText="Customer">
> > <ItemStyle VerticalAlign="Top"></ItemStyle>
> > <ItemTemplate>
> > <b>
> > <%# DataBinder.Eval(Container.DataItem, "CompanyName") %>
> > </b>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "Address" ) %>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "City" ) %>
> > ,
> > <%# DataBinder.Eval(Container.DataItem, "Region") %>
> > <%# DataBinder.Eval(Container.DataItem, "PostalCode" ) %>
> > <br>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "ContactName" ) %>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "ContactTitle" ) %>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "Phone" ) %>
> > </ItemTemplate>
> > </asp:TemplateColumn>
> > <asp:TemplateColumn ItemStyle-VerticalAlign="Top"
> > HeaderText="Orders">
> > <%-- Embedded DataGrid will go here --%>
> > </asp:TemplateColumn>
> > </Columns>
> > </aspataGrid>
> > <!-- End DataGrid -->
> > </form>
> > <!-- End Web Form -->
> > </body>
> > </HTML>
> >
> > ---------------------
> > CODE BEHIND
> > ----------------------
> > using System;
> > using System.Data;
> > using System.Data.SqlClient;
> > using System.Drawing;
> > using System.Web;
> > using System.Web.UI;
> > using System.Web.UI.WebControls;
> > using System.Web.UI.HtmlControls;
> > using System.Configuration;
> >
> > namespace MasterDetail
> > {
> > public class CustomerOrderDataGrid : System.Web.UI.Page
> > {
> > protected DataGrid CustomerDataGrid;
> > private DataSet ds = new DataSet();
> >
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM Orders";
> > string conString =
> > "server=localhost;database=Northwind;uid=sa;pwd=ti etronix;";
> >
> > SqlDataAdapter sda = new SqlDataAdapter(sqlStmt, conString);
> >
> > sda.Fill(ds);
> > ds.Tables[0].TableName = "Customers";
> > ds.Tables[1].TableName = "Orders";
> >
> > CustomerDataGrid.DataSource = ds.Tables["Customers"];
> > CustomerDataGrid.DataBind();
> > }
> >
> > //Use the OnItemDataBound event handler to dynamically add an embedded
> > DataGrid
> > protected void CustomerDataGrid_OnItemDataBound(object sender,
> > DataGridItemEventArgs e)
> > {
> > //When each row is created in the DataGrid, eval the ItemType
> > if(e.Item.ItemType == ListItemType.Item ||
> > e.Item.ItemType == ListItemType.AlternatingItem)
> > {
> > //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.Horizontal;
> > OrdersDataGrid.BorderColor = Color.FromName("Black");
> >
> > OrdersDataGrid.ItemStyle.Font.Name = "Verdana";
> > OrdersDataGrid.ItemStyle.Font.Size = FontUnit.XSmall;
> >
> > OrdersDataGrid.AlternatingItemStyle.BackColor =
> > Color.FromName("LightGray");
> >
> > OrdersDataGrid.ShowHeader = true;
> > OrdersDataGrid.HeaderStyle.BackColor = Color.FromName("Black");
> > OrdersDataGrid.HeaderStyle.ForeColor = Color.FromName("White");
> > OrdersDataGrid.HeaderStyle.Font.Bold = true;
> > OrdersDataGrid.HeaderStyle.Font.Size = FontUnit.XSmall;
> >
> >
> > //Do not autogenerate columns.
> > OrdersDataGrid.AutoGenerateColumns = 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.Wrap = false;
> > //Add the BoundColumn to the OrdersDataGrid.
> > OrdersDataGrid.Columns.Add(bc);
> >
> > //Order Date
> > bc = new BoundColumn();
> > bc.HeaderText = "Order Date";
> > bc.DataField = "OrderDate";
> > bc.DataFormatString="{0:d}";
> > bc.ItemStyle.Wrap = false;
> > OrdersDataGrid.Columns.Add(bc);
> >
> > //Required Date
> > bc = new BoundColumn();
> > bc.HeaderText = "Required Date";
> > bc.DataField = "RequiredDate";
> > bc.DataFormatString="{0:d}";
> > bc.ItemStyle.Wrap = false;
> > OrdersDataGrid.Columns.Add(bc);
> >
> > //Shipped Date
> > bc = new BoundColumn();
> > bc.HeaderText = "Shipped Date";
> > bc.DataField = "ShippedDate";
> > bc.DataFormatString="{0:d}";
> > bc.ItemStyle.Wrap = 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.RowFilter = "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.WebControls.DataGridItemEventHandler (this.OrdersDataGrid_ItemDataBound);
> > //Add the OrdersDataGrid to the BooksDataGrid.
> > e.Item.Cells[3].Controls.Add(OrdersDataGrid);
> > }
> > }
> >
> > private void OrdersDataGrid_ItemDataBound(object sender,
> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> > {
> > //CODE NEVER REACHES HERE.
> > int i=1;
> > i=10 + 12;
> > }
> >
> > override protected void OnInit(EventArgs e)
> > {
> > //
> > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> > //
> > InitializeComponent();
> > base.OnInit(e);
> > }
> >
> > private void InitializeComponent()
> > {
> > this.CustomerDataGrid.ItemCreated += new
> > System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_ItemCreated);
> > //this.CustomerDataGrid.ItemDataBound += new
> > System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_OnItemDataBound);
> > this.Load += new System.EventHandler(this.Page_Load);
> >
> > }
> >
> > private void CustomerDataGrid_ItemCreated(object sender,
> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> > {
> > int i=1;
> > i=10 + 12;
> > }
> > }
> > }
> >
> >
> >

 
Reply With Quote
 
Girish
Guest
Posts: n/a
 
      07-18-2005
Thanks Phillip. This helps.

Girish

"Phillip Williams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 programmatically. 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 CustomerDataGrid_OnItemDataBound(object
>> sender,
>> DataGridItemEventArgs e) method. This is where I register the event and
>> place the programmatically 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="MasterDetail.CustomerOrderDataGrid"
>> EnableViewState="False" CodeBehind="CustomerOrderDataGrid.aspx.cs"
>> AutoEventWireup="false" %>
>> <HTML>
>> <body style="FONT: x-small Verdana, Arial, sans-serif">
>> <!-- Begin Web Form -->
>> <form id="CustomerOrderDataGrid" method="post" runat="server">
>> <p><a href="/DayOfDotNet/">Parent Directory</a></p>
>> <!-- Begin DataGrid -->
>> <aspataGrid id="CustomerDataGrid" runat="server"
>> AutoGenerateColumns="False" CellPadding="2"
>> CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
>> BorderColor="Black" BorderWidth="1"
>> GridLines="Horizontal"
>> OnItemDataBound="CustomerDataGrid_OnItemDataBound"
>> EnableViewState="False">
>> <AlternatingItemStyle BackColor="Tan"></AlternatingItemStyle>
>> <ItemStyle Font-Size="X-Small"></ItemStyle>
>> <HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
>> ForeColor="White" BackColor="Maroon"></HeaderStyle>
>> <Columns>
>> <asp:BoundColumn Visible="False"
>> DataField="CustomerID"></asp:BoundColumn>
>> <asp:HyperLinkColumn
>> DataTextField="CustomerID"
>> DataNavigateUrlField="CustomerID"
>>
>> DataNavigateUrlFormatString="OrderDetailDataGrid.a spx?customerid={0}"
>> HeaderText="ID"
>> ItemStyle-VerticalAlign="Top" />
>>
>> <asp:TemplateColumn HeaderText="Customer">
>> <ItemStyle VerticalAlign="Top"></ItemStyle>
>> <ItemTemplate>
>> <b>
>> <%# DataBinder.Eval(Container.DataItem, "CompanyName") %>
>> </b>
>> <br>
>> <%# DataBinder.Eval(Container.DataItem, "Address" ) %>
>> <br>
>> <%# DataBinder.Eval(Container.DataItem, "City" ) %>
>> ,
>> <%# DataBinder.Eval(Container.DataItem, "Region") %>
>> <%# DataBinder.Eval(Container.DataItem, "PostalCode" ) %>
>> <br>
>> <br>
>> <%# DataBinder.Eval(Container.DataItem, "ContactName" ) %>
>> <br>
>> <%# DataBinder.Eval(Container.DataItem, "ContactTitle" ) %>
>> <br>
>> <%# DataBinder.Eval(Container.DataItem, "Phone" ) %>
>> </ItemTemplate>
>> </asp:TemplateColumn>
>> <asp:TemplateColumn ItemStyle-VerticalAlign="Top"
>> HeaderText="Orders">
>> <%-- Embedded DataGrid will go here --%>
>> </asp:TemplateColumn>
>> </Columns>
>> </aspataGrid>
>> <!-- End DataGrid -->
>> </form>
>> <!-- End Web Form -->
>> </body>
>> </HTML>
>>
>> ---------------------
>> CODE BEHIND
>> ----------------------
>> using System;
>> using System.Data;
>> using System.Data.SqlClient;
>> using System.Drawing;
>> using System.Web;
>> using System.Web.UI;
>> using System.Web.UI.WebControls;
>> using System.Web.UI.HtmlControls;
>> using System.Configuration;
>>
>> namespace MasterDetail
>> {
>> public class CustomerOrderDataGrid : System.Web.UI.Page
>> {
>> protected DataGrid CustomerDataGrid;
>> private DataSet ds = new DataSet();
>>
>> private void Page_Load(object sender, System.EventArgs e)
>> {
>> string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM
>> Orders";
>> string conString =
>> "server=localhost;database=Northwind;uid=sa;pwd=ti etronix;";
>>
>> SqlDataAdapter sda = new SqlDataAdapter(sqlStmt, conString);
>>
>> sda.Fill(ds);
>> ds.Tables[0].TableName = "Customers";
>> ds.Tables[1].TableName = "Orders";
>>
>> CustomerDataGrid.DataSource = ds.Tables["Customers"];
>> CustomerDataGrid.DataBind();
>> }
>>
>> //Use the OnItemDataBound event handler to dynamically add an embedded
>> DataGrid
>> protected void CustomerDataGrid_OnItemDataBound(object sender,
>> DataGridItemEventArgs e)
>> {
>> //When each row is created in the DataGrid, eval the ItemType
>> if(e.Item.ItemType == ListItemType.Item ||
>> e.Item.ItemType == ListItemType.AlternatingItem)
>> {
>> //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.Horizontal;
>> OrdersDataGrid.BorderColor = Color.FromName("Black");
>>
>> OrdersDataGrid.ItemStyle.Font.Name = "Verdana";
>> OrdersDataGrid.ItemStyle.Font.Size = FontUnit.XSmall;
>>
>> OrdersDataGrid.AlternatingItemStyle.BackColor =
>> Color.FromName("LightGray");
>>
>> OrdersDataGrid.ShowHeader = true;
>> OrdersDataGrid.HeaderStyle.BackColor = Color.FromName("Black");
>> OrdersDataGrid.HeaderStyle.ForeColor = Color.FromName("White");
>> OrdersDataGrid.HeaderStyle.Font.Bold = true;
>> OrdersDataGrid.HeaderStyle.Font.Size = FontUnit.XSmall;
>>
>>
>> //Do not autogenerate columns.
>> OrdersDataGrid.AutoGenerateColumns = 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.Wrap = false;
>> //Add the BoundColumn to the OrdersDataGrid.
>> OrdersDataGrid.Columns.Add(bc);
>>
>> //Order Date
>> bc = new BoundColumn();
>> bc.HeaderText = "Order Date";
>> bc.DataField = "OrderDate";
>> bc.DataFormatString="{0:d}";
>> bc.ItemStyle.Wrap = false;
>> OrdersDataGrid.Columns.Add(bc);
>>
>> //Required Date
>> bc = new BoundColumn();
>> bc.HeaderText = "Required Date";
>> bc.DataField = "RequiredDate";
>> bc.DataFormatString="{0:d}";
>> bc.ItemStyle.Wrap = false;
>> OrdersDataGrid.Columns.Add(bc);
>>
>> //Shipped Date
>> bc = new BoundColumn();
>> bc.HeaderText = "Shipped Date";
>> bc.DataField = "ShippedDate";
>> bc.DataFormatString="{0:d}";
>> bc.ItemStyle.Wrap = 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.RowFilter = "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.WebControls.DataGridItemEventHandler (this.OrdersDataGrid_ItemDataBound);
>> //Add the OrdersDataGrid to the BooksDataGrid.
>> e.Item.Cells[3].Controls.Add(OrdersDataGrid);
>> }
>> }
>>
>> private void OrdersDataGrid_ItemDataBound(object sender,
>> System.Web.UI.WebControls.DataGridItemEventArgs e)
>> {
>> //CODE NEVER REACHES HERE.
>> int i=1;
>> i=10 + 12;
>> }
>>
>> override protected void OnInit(EventArgs e)
>> {
>> //
>> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
>> //
>> InitializeComponent();
>> base.OnInit(e);
>> }
>>
>> private void InitializeComponent()
>> {
>> this.CustomerDataGrid.ItemCreated += new
>> System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_ItemCreated);
>> //this.CustomerDataGrid.ItemDataBound += new
>> System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_OnItemDataBound);
>> this.Load += new System.EventHandler(this.Page_Load);
>>
>> }
>>
>> private void CustomerDataGrid_ItemCreated(object sender,
>> System.Web.UI.WebControls.DataGridItemEventArgs e)
>> {
>> int i=1;
>> i=10 + 12;
>> }
>> }
>> }
>>
>>
>>



 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      07-19-2005
Good one Phillips!

"Phillip Williams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 programmatically. 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 CustomerDataGrid_OnItemDataBound(object

sender,
> > DataGridItemEventArgs e) method. This is where I register the event and
> > place the programmatically 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="MasterDetail.CustomerOrderDataGrid"
> > EnableViewState="False" CodeBehind="CustomerOrderDataGrid.aspx.cs"
> > AutoEventWireup="false" %>
> > <HTML>
> > <body style="FONT: x-small Verdana, Arial, sans-serif">
> > <!-- Begin Web Form -->
> > <form id="CustomerOrderDataGrid" method="post" runat="server">
> > <p><a href="/DayOfDotNet/">Parent Directory</a></p>
> > <!-- Begin DataGrid -->
> > <aspataGrid id="CustomerDataGrid" runat="server"
> > AutoGenerateColumns="False" CellPadding="2"
> > CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
> > BorderColor="Black" BorderWidth="1"
> > GridLines="Horizontal"
> > OnItemDataBound="CustomerDataGrid_OnItemDataBound"

EnableViewState="False">
> > <AlternatingItemStyle BackColor="Tan"></AlternatingItemStyle>
> > <ItemStyle Font-Size="X-Small"></ItemStyle>
> > <HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
> > ForeColor="White" BackColor="Maroon"></HeaderStyle>
> > <Columns>
> > <asp:BoundColumn Visible="False"
> > DataField="CustomerID"></asp:BoundColumn>
> > <asp:HyperLinkColumn
> > DataTextField="CustomerID"
> > DataNavigateUrlField="CustomerID"
> >

DataNavigateUrlFormatString="OrderDetailDataGrid.a spx?customerid={0}"
> > HeaderText="ID"
> > ItemStyle-VerticalAlign="Top" />
> >
> > <asp:TemplateColumn HeaderText="Customer">
> > <ItemStyle VerticalAlign="Top"></ItemStyle>
> > <ItemTemplate>
> > <b>
> > <%# DataBinder.Eval(Container.DataItem, "CompanyName") %>
> > </b>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "Address" ) %>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "City" ) %>
> > ,
> > <%# DataBinder.Eval(Container.DataItem, "Region") %>
> > <%# DataBinder.Eval(Container.DataItem, "PostalCode" ) %>
> > <br>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "ContactName" ) %>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "ContactTitle" ) %>
> > <br>
> > <%# DataBinder.Eval(Container.DataItem, "Phone" ) %>
> > </ItemTemplate>
> > </asp:TemplateColumn>
> > <asp:TemplateColumn ItemStyle-VerticalAlign="Top"
> > HeaderText="Orders">
> > <%-- Embedded DataGrid will go here --%>
> > </asp:TemplateColumn>
> > </Columns>
> > </aspataGrid>
> > <!-- End DataGrid -->
> > </form>
> > <!-- End Web Form -->
> > </body>
> > </HTML>
> >
> > ---------------------
> > CODE BEHIND
> > ----------------------
> > using System;
> > using System.Data;
> > using System.Data.SqlClient;
> > using System.Drawing;
> > using System.Web;
> > using System.Web.UI;
> > using System.Web.UI.WebControls;
> > using System.Web.UI.HtmlControls;
> > using System.Configuration;
> >
> > namespace MasterDetail
> > {
> > public class CustomerOrderDataGrid : System.Web.UI.Page
> > {
> > protected DataGrid CustomerDataGrid;
> > private DataSet ds = new DataSet();
> >
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > string sqlStmt = "SELECT top 2 * FROM Customers; SELECT * FROM

Orders";
> > string conString =
> > "server=localhost;database=Northwind;uid=sa;pwd=ti etronix;";
> >
> > SqlDataAdapter sda = new SqlDataAdapter(sqlStmt, conString);
> >
> > sda.Fill(ds);
> > ds.Tables[0].TableName = "Customers";
> > ds.Tables[1].TableName = "Orders";
> >
> > CustomerDataGrid.DataSource = ds.Tables["Customers"];
> > CustomerDataGrid.DataBind();
> > }
> >
> > //Use the OnItemDataBound event handler to dynamically add an embedded
> > DataGrid
> > protected void CustomerDataGrid_OnItemDataBound(object sender,
> > DataGridItemEventArgs e)
> > {
> > //When each row is created in the DataGrid, eval the ItemType
> > if(e.Item.ItemType == ListItemType.Item ||
> > e.Item.ItemType == ListItemType.AlternatingItem)
> > {
> > //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.Horizontal;
> > OrdersDataGrid.BorderColor = Color.FromName("Black");
> >
> > OrdersDataGrid.ItemStyle.Font.Name = "Verdana";
> > OrdersDataGrid.ItemStyle.Font.Size = FontUnit.XSmall;
> >
> > OrdersDataGrid.AlternatingItemStyle.BackColor =
> > Color.FromName("LightGray");
> >
> > OrdersDataGrid.ShowHeader = true;
> > OrdersDataGrid.HeaderStyle.BackColor = Color.FromName("Black");
> > OrdersDataGrid.HeaderStyle.ForeColor = Color.FromName("White");
> > OrdersDataGrid.HeaderStyle.Font.Bold = true;
> > OrdersDataGrid.HeaderStyle.Font.Size = FontUnit.XSmall;
> >
> >
> > //Do not autogenerate columns.
> > OrdersDataGrid.AutoGenerateColumns = 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.Wrap = false;
> > //Add the BoundColumn to the OrdersDataGrid.
> > OrdersDataGrid.Columns.Add(bc);
> >
> > //Order Date
> > bc = new BoundColumn();
> > bc.HeaderText = "Order Date";
> > bc.DataField = "OrderDate";
> > bc.DataFormatString="{0:d}";
> > bc.ItemStyle.Wrap = false;
> > OrdersDataGrid.Columns.Add(bc);
> >
> > //Required Date
> > bc = new BoundColumn();
> > bc.HeaderText = "Required Date";
> > bc.DataField = "RequiredDate";
> > bc.DataFormatString="{0:d}";
> > bc.ItemStyle.Wrap = false;
> > OrdersDataGrid.Columns.Add(bc);
> >
> > //Shipped Date
> > bc = new BoundColumn();
> > bc.HeaderText = "Shipped Date";
> > bc.DataField = "ShippedDate";
> > bc.DataFormatString="{0:d}";
> > bc.ItemStyle.Wrap = 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.RowFilter = "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.WebControls.DataGridItemEventHandler (this.OrdersDataGrid_ItemD
ataBound);
> > //Add the OrdersDataGrid to the BooksDataGrid.
> > e.Item.Cells[3].Controls.Add(OrdersDataGrid);
> > }
> > }
> >
> > private void OrdersDataGrid_ItemDataBound(object sender,
> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> > {
> > //CODE NEVER REACHES HERE.
> > int i=1;
> > i=10 + 12;
> > }
> >
> > override protected void OnInit(EventArgs e)
> > {
> > //
> > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> > //
> > InitializeComponent();
> > base.OnInit(e);
> > }
> >
> > private void InitializeComponent()
> > {
> > this.CustomerDataGrid.ItemCreated += new
> >

System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_Ite
mCreated);
> > //this.CustomerDataGrid.ItemDataBound += new
> >

System.Web.UI.WebControls.DataGridItemEventHandler (this.CustomerDataGrid_OnI
temDataBound);
> > this.Load += new System.EventHandler(this.Page_Load);
> >
> > }
> >
> > private void CustomerDataGrid_ItemCreated(object sender,
> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> > {
> > int i=1;
> > i=10 + 12;
> > }
> > }
> > }
> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with DataList's ItemDataBound Event Nathan Sokalski ASP .Net 2 05-27-2007 07:44 AM
GV Databound Event vs DG ItemDataBound Event GaryDean ASP .Net 1 08-18-2006 03:47 AM
ItemDataBound Event - How to access the previous record when this event is raised in DataGrid? NH ASP .Net Datagrid Control 2 12-17-2004 03:58 PM
Problem with ItemDAtaBound event of datalist Bill Yeager ASP .Net Datagrid Control 1 10-26-2004 02:28 PM
ItemDataBound not received by grid in table? James G. Beldock ASP .Net 0 07-24-2003 04:38 PM



Advertisments