469,910 Members | 1,490 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,910 developers. It's quick & easy.

Getting value from GridView

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
Jan 4 '08 #1
3 9193
"David C" <dl*****@lifetimeinc.comwrote in message
news:uV**************@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/lib....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

Jan 4 '08 #2
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]" <ma**@markNOSPAMrae.netwrote in message
news:uj**************@TK2MSFTNGP02.phx.gbl...
"David C" <dl*****@lifetimeinc.comwrote in message
news:uV**************@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/lib....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

Jan 4 '08 #3
"David C" <dl*****@lifetimeinc.comwrote in message
news:u8**************@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

Jan 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by melanieab | last post: by
4 posts views Thread by bushi | last post: by
reply views Thread by David Lozzi | last post: by
3 posts views Thread by koneru9999 | last post: by
4 posts views Thread by TisMe | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.