Getting value from GridView
am 04.01.2008 23:25:16 von David C
I have a GridView and when the SelectedIndexChange occurs I want to put the
value of a BoundField into a TextBox (txtPropertyID) on the page. Below is
the code I am using but it is not getting the value. Can someone help?
Thanks
David
Protected Sub gvPropertyClosings_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs)
Dim gvrow As GridViewRow = gvPropertyClosings.SelectedRow
txtPropertyID.Text =
Convert.ToString(DataBinder.Eval(gvrow.DataItem, "PropertyID"))
End Sub
Re: Getting value from GridView
am 04.01.2008 23:39:03 von mark
"David C" wrote in message
news:uVS1FDyTIHA.4532@TK2MSFTNGP02.phx.gbl...
> Below is the code I am using but it is not getting the value.
That's right - the DataItem property is available only during the GridView's
RowDataBound event:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webco ntrols.gridviewrow.dataitem.aspx
> Can someone help?
Store the value during the RowDataBound event, either as part of the
GridView's DataKeyNames property or in a hidden field in one of the row's
cells...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Getting value from GridView
am 04.01.2008 23:55:15 von David C
But I only want the value of the Selected row cell. How do I specify since
RowDataBound fires on each record correct?
David
"Mark Rae [MVP]" wrote in message
news:ujOuNKyTIHA.5264@TK2MSFTNGP02.phx.gbl...
> "David C" wrote in message
> news:uVS1FDyTIHA.4532@TK2MSFTNGP02.phx.gbl...
>
>> Below is the code I am using but it is not getting the value.
>
> That's right - the DataItem property is available only during the
> GridView's RowDataBound event:
> http://msdn2.microsoft.com/en-us/library/system.web.ui.webco ntrols.gridviewrow.dataitem.aspx
>
>> Can someone help?
>
> Store the value during the RowDataBound event, either as part of the
> GridView's DataKeyNames property or in a hidden field in one of the row's
> cells...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
Re: Getting value from GridView
am 05.01.2008 01:18:24 von mark
"David C" wrote in message
news:u8T01TyTIHA.3676@TK2MSFTNGP06.phx.gbl...
> But I only want the value of the Selected row cell. How do I specify
> since RowDataBound fires on each record correct?
No, you're missing the point...
You're trying to interrogate the DataItem property in the GridView's
SelectedIndexChanged event, but the DataItem property is available only in
the RowDataBound event...
That's why if, in any event other than the RowDataBound event, you require
any value from the the GridView's underlying data source which is not bound
to the GridView's cells or DataKeyNames property, you'll need to add it to
the GridView during the RowDataBound event...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net