Why it is null?

E

etam

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

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

Thanks,
Etam.
 
M

Mark Rae

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...?
 
E

etam

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.
 
E

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.
 
E

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.
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top