Wednesday, March 28, 2012

Why it is null?

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

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

Thanks,
Etam."etam" <odwrotnie@.gmail.comwrote in message
news:1180188109.472898.157020@.k79g2000hse.googlegr oups.com...

Quote:

Originally Posted by

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:GridViewtag...?

--
http://www.markrae.net
Mark Rae napisa (a):

Quote:

Originally Posted by

Have you forgotten to specify the DataKeyNames property in the
<asp:GridViewtag...?


No, it is set to "id".
"etam" <odwrotnie@.gmail.comwrote in message
news:1180211758.127237.49550@.o5g2000hsb.googlegrou ps.com...

Quote:

Originally Posted by

Mark Rae napisa (a):

Quote:

Originally Posted by

>Have you forgotten to specify the DataKeyNames property in the
><asp:GridViewtag...?


>
No, it is set to "id".


?

You actually have a field in your database table called 'id'...?

--
http://www.markrae.net
On 26 Maj, 22:53, "Mark Rae" <m...@.markNOSPAMrae.netwrote:

Quote:

Originally Posted by

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.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"etam" <odwrotnie@.gmail.comwrote in message
news:1180188109.472898.157020@.k79g2000hse.googlegr oups.com...

Quote:

Originally Posted by

Hi, does anyone know why o == null?!
>
protected void ShowProjectsGridView_SelectedIndexChanged(object
sender, EventArgs e) {
Object o = ProjectsGridView.SelectedRow.DataItem;
//...
}
>
Thanks,
Etam.
>


On 27 Maj, 09:30, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

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.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"etam" <odwrotnie@.gmail.comwrote in message
news:1180253280.035540.8080@.h2g2000hsg.googlegroup s.com...

Quote:

Originally Posted by

On 27 Maj, 09:30, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

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


On 27 Maj, 11:34, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

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.
msdn library is good enough:

http://msdn2.microsoft.com/en-us/li...dataitem.asp x
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"etam" <odwrotnie@.gmail.comwrote in message
news:1180262101.295257.253430@.w5g2000hsg.googlegro ups.com...

Quote:

Originally Posted by

On 27 Maj, 11:34, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

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

0 comments:

Post a Comment