DataItem property = NULL during paging, why??!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm subscribing to the RowCreated event during GridView render process to
modify properties of individual rows. All works great when there is no paging
involved but once I specify that I'd like to use paging my code works only on
the first page.
Please look at the code; when the first page loads ID is set properly (for
each row) but when you navigate to another one you'd get NullReference error.
Why, I don't get it??

Sample pseudo-code:
void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int ID = ((DataRowView)e.Row.DataItem)["UserID"]
}
}
 
I was accessing DataItem property in respoonse to a wrong event
(RowCreated). DataItem property is only available in RowDataBound event which
fires before RowCreated event. Responding to this event allows me to examine
individual values in each row without running to the issue described in my
previous post. Thanks.
 
Back
Top