Gridview - Pull value from one cell in one row


P

pvong

Hi, I'm a newbie and I'm looking for some help. I'm programming in VB.Net.

I have a simple gridview and when the user hits the Edit link, the gridview
changes to edit mode. I replaced the Textboxes with labels and I turn off
the Update command because I want to write my own update command. I can not
figure out how to pull the value from a cell in the row the user hit Edit
on.

Example: User hits edit on row 10 and the value I want to pull in in column
5 and is a Label with the ID of AnswerID. How do I get that value. This is
what I've tried and it didn't work.

Gridview.findcontrol("AnswerID").tostring


Thanks!
 
Ad

Advertisements

R

Riki

pvong said:
Hi, I'm a newbie and I'm looking for some help. I'm programming in
VB.Net.
I have a simple gridview and when the user hits the Edit link, the
gridview changes to edit mode. I replaced the Textboxes with labels
and I turn off the Update command because I want to write my own
update command. I can not figure out how to pull the value from a
cell in the row the user hit Edit on.

Example: User hits edit on row 10 and the value I want to pull in in
column 5 and is a Label with the ID of AnswerID. How do I get that
value. This is what I've tried and it didn't work.

Gridview.findcontrol("AnswerID").tostring

Gridview.Rows(GridView.EditIndex).Cells(5).FindControl("AnswerID").ToString()

Note that column 5 is the sixth column here (starts from 0).
 
P

pvong

Thanks for replying. To test this, I created another label (Results)
outside of the gridview to show the value to make sure it works. When I do
this, Results shows this error message.

System.Web.UI.WebControls.Label
 
R

Riki

pvong said:
Thanks for replying. To test this, I created another label (Results)
outside of the gridview to show the value to make sure it works. When I do
this, Results shows this error message.

System.Web.UI.WebControls.Label

Gridview.Rows(GridView.EditIndex).Cells(5).FindControl("AnswerID").ToString()
produces the name of the control.

To get the content, use (VB.NET)
CType(Gridview.Rows(GridView.EditIndex).Cells(5).FindControl("AnswerID"),Label).Text
In C#:
((Label)Gridview.Rows(GridView.EditIndex).Cells(5).FindControl("AnswerID")).Text
 
Ad

Advertisements

P

pvong

Perfect! Thanks!
Riki said:
Gridview.Rows(GridView.EditIndex).Cells(5).FindControl("AnswerID").ToString()
produces the name of the control.

To get the content, use (VB.NET)
CType(Gridview.Rows(GridView.EditIndex).Cells(5).FindControl("AnswerID"),Label).Text
In C#:
((Label)Gridview.Rows(GridView.EditIndex).Cells(5).FindControl("AnswerID")).Text
 

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

Top