DataItem property = NULL during paging, why??!

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"]
}
}
 
G

Guest

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.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top