Web Control that inherits the DataGrid

J

Jonas Nilsson

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top