Web Control that inherits the DataGrid

Discussion in 'ASP .Net Datagrid Control' started by Jonas Nilsson, Sep 5, 2003.

  1. Hi!

    Does anyone have a sample on how i can inherit the datagrid in a Web Control
    and bind it to a datasource.
    And then add template columns and add data from the datasource into the
    columns

    My Web Control inherits the DataGrid, i bind the control to a datasource
    (DataReader) in my aspx code (Page_Load event)

    But i can't get data from the DataItem in OnItemDataBound event in my Web
    Control.

    protected override void OnItemDataBound(DataGridItemEventArgs e)
    {
    LinkButton lb = new LinkButton();
    lb.ID = "lbNav";

    *** This row causes a "Object reference not set to an instance of an
    object" ***
    lb.Text = ((DataRowView)e.Item.DataItem).Row.ItemArray[1].ToString();

    e.Item.Cells[0].Controls.Add(lb);
    base.OnItemDataBound (e);
    }

    /Jonas
    Jonas Nilsson, Sep 5, 2003
    #1
    1. Advertising

  2. Jonas Nilsson

    Noel Hoo Guest

    Morning Jonas,

    Try this link
    http://msdn.microsoft.com/msdnmag/issues/01/10/cutting/cutting0110.asp
    Build a Variety of Custom Controls Based on the DataGrid Control by Dino
    Esposito

    He rocks!!

    Hope this helps,

    --
    Noel Hoo
    -centre.com

    "Jonas Nilsson" <> wrote in message
    news:...
    > Hi!
    >
    > Does anyone have a sample on how i can inherit the datagrid in a Web

    Control
    > and bind it to a datasource.
    > And then add template columns and add data from the datasource into the
    > columns
    >
    > My Web Control inherits the DataGrid, i bind the control to a datasource
    > (DataReader) in my aspx code (Page_Load event)
    >
    > But i can't get data from the DataItem in OnItemDataBound event in my Web
    > Control.
    >
    > protected override void OnItemDataBound(DataGridItemEventArgs e)
    > {
    > LinkButton lb = new LinkButton();
    > lb.ID = "lbNav";
    >
    > *** This row causes a "Object reference not set to an instance of an
    > object" ***
    > lb.Text = ((DataRowView)e.Item.DataItem).Row.ItemArray[1].ToString();
    >
    > e.Item.Cells[0].Controls.Add(lb);
    > base.OnItemDataBound (e);
    > }
    >
    > /Jonas
    >
    >
    >
    Noel Hoo, Sep 8, 2003
    #2
    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. ton

    Inherits from web user control

    ton, Oct 17, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    390
    Hans Kesting
    Oct 17, 2003
  2. Tee
    Replies:
    1
    Views:
    368
    John Saunders
    Jun 8, 2004
  3. Alex Nitulescu
    Replies:
    0
    Views:
    347
    Alex Nitulescu
    Feb 22, 2005
  4. ton
    Replies:
    1
    Views:
    1,014
    Teemu Keiski
    Jun 24, 2007
  5. D.G.
    Replies:
    0
    Views:
    145
Loading...

Share This Page