Why it is null?

  • Thread starter Thread starter etam
  • Start date Start date
E

etam

Hi, does anyone know why o == null?!

protected void ShowProjectsGridView_SelectedIndexChanged(object
sender, EventArgs e) {
Object o = ProjectsGridView.SelectedRow.DataItem;
//...
}

Thanks,
Etam.
 
Hi, does anyone know why o == null?!

protected void ShowProjectsGridView_SelectedIndexChanged(object
sender, EventArgs e) {
Object o = ProjectsGridView.SelectedRow.DataItem;
//...
}

Thanks,
Etam.

Have you forgotten to specify the DataKeyNames property in the
<asp:GridView> tag...?
 
You actually have a field in your database table called 'id'...???

Yes :). Strange for me is that
Int64 id = (Int64)ProjectsGridView.SelectedDataKey.Value;
is OK :/.

Regards,
Etam.
 
DataItem property is available only in RowDataBound. It makes a lot of sense
if you think about it since this event is the only time when grid items
actually meet their datasources.

So what for is the DataItem property in GridViewRow?

Regards,
Etam.
 
It does get the data object that supplies data to the rows but it does it
only during the RowDataBound event. In all other times it returns null.

Thanks! It explains a lot ;). Could You give me a link where can I
read about it from?

Regards,
Etam.
 
Back
Top