Getting value from GridView

D

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
 
M

Mark Rae [MVP]

D

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
 
M

Mark Rae [MVP]

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

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,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top