Getting value from GridView

  • Thread starter Thread starter David C
  • Start date Start date
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
 
But I only want the value of the Selected row cell. How do I specify since
RowDataBound fires on each record correct?

David
 
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

Back
Top