Grid within a Grid ItemDataBound event problem

Discussion in 'ASP .Net' started by Girish, Jul 18, 2005.

  1. Girish

    Girish Guest

    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 -->
    <asp:DataGrid 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.aspx?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>
    </asp:DataGrid>
    <!-- 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=tietronix;";

    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;
    }
    }
    }
    Girish, Jul 18, 2005
    #1
    1. Advertising

  2. 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 -->
    > <asp:DataGrid 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.aspx?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>
    > </asp:DataGrid>
    > <!-- 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=tietronix;";
    >
    > 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;
    > }
    > }
    > }
    >
    >
    >
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Jul 18, 2005
    #2
    1. Advertising

  3. 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 -->
    > > <asp:DataGrid 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.aspx?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>
    > > </asp:DataGrid>
    > > <!-- 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=tietronix;";
    > >
    > > 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;
    > > }
    > > }
    > > }
    > >
    > >
    > >
    =?Utf-8?B?dmluYXk=?=, Jul 18, 2005
    #3
  4. Girish

    Girish Guest

    Thanks Phillip. This helps.

    Girish

    "Phillip Williams" <> wrote in message
    news:...
    > 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 -->
    >> <asp:DataGrid 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.aspx?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>
    >> </asp:DataGrid>
    >> <!-- 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=tietronix;";
    >>
    >> 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;
    >> }
    >> }
    >> }
    >>
    >>
    >>
    Girish, Jul 19, 2005
    #4
  5. Good one Phillips!

    "Phillip Williams" <> wrote in message
    news:...
    > 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 -->
    > > <asp:DataGrid 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.aspx?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>
    > > </asp:DataGrid>
    > > <!-- 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=tietronix;";
    > >
    > > 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;
    > > }
    > > }
    > > }
    > >
    > >
    > >
    Patrick.O.Ige, Jul 19, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James G. Beldock

    ItemDataBound not received by grid in table?

    James G. Beldock, Jul 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    438
    James G. Beldock
    Jul 24, 2003
  2. GaryDean
    Replies:
    1
    Views:
    8,691
    Walter Wang [MSFT]
    Aug 18, 2006
  3. Nathan Sokalski

    Problem with DataList's ItemDataBound Event

    Nathan Sokalski, May 25, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    566
    Eliyahu Goldin
    May 27, 2007
  4. Bill Yeager

    Problem with ItemDAtaBound event of datalist

    Bill Yeager, Oct 25, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    134
    bill yeager
    Oct 26, 2004
  5. NH
    Replies:
    2
    Views:
    528
    Andrew L. Van Slaars
    Dec 17, 2004
Loading...

Share This Page