Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello.

I just want to ask how can I get or retrieve the current row that I select on the gridview.. I'm using the VB language.. I found this answer click here
but it didn't work :(

can anyone tell me the answer?? :(

textbox1.text = ???????

badly needed. thanks! :)
Posted
Comments
Yusuf 14-Feb-11 21:52pm    
I moved your answer as a comment to the answer below.

Have a look here[^]. This ought to help you out.
 
Share this answer
 
Comments
Venkatesh Mookkan 14-Feb-11 23:14pm    
Abhinav, he is talking about ASP.NET. ;)
The link you provided is for Windows Forms. It does not work like that.

Try the below,

CS
C#
(GridView1.Rows[YOUR_ROW_INDEX].FindControl(YOUR_CONTROL_NAME) as TextBox).Text


VB
VB
CType(GridView1.Rows(YOUR_ROW_INDEX).FindControl(YOUR_CONTROL_NAME), TextBox).Text


or

CS
C#
(GridView1.Rows[YOUR_ROW_INDEX].Cells[YOUR_CELL_INDEX].Controls(YOUR_CONTROL_INDEX) as TextBox).Text


VB
VB
CType(GridView1.Rows[YOUR_ROW_INDEX].Cells[YOUR_CELL_INDEX].Controls(YOUR_CONTROL_INDEX), TextBox).Text


Mark it as answer if it is helpful
 
Share this answer
 
v4
Comments
Yusuf 14-Feb-11 21:51pm    
MOVED FROM OP COMMENT:

sir, is the control_name = the field names from database?
sir here's my sample code
Protected Sub Gridview1_SelectedIndexChanged(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)

txtLName.Text = CType(GridView1.Row(1).FindControl(YOUR_CONTROL_NAME), TextBox).Text
End Sub

but there is some error,
states that: "row is not a member of system.web.ui.webcontrols.gridview"
thanks for the response sir :)
I hope you reply again :D
Venkatesh Mookkan 14-Feb-11 21:54pm    
Sorry, my bad. I corrected it. Its "Rows". YOUR_CONTROL_NAME is the name you given for that server control. If you haven't given any name, use the second option mentioned in the above answer.
sevengenn 14-Feb-11 22:00pm    
sir, can you give sample to declare the control_name. :)
thanks sir.
Venkatesh Mookkan 14-Feb-11 22:02pm    
Use this and get going,

CType(GridView1.Rows[1].Cells[YOUR_CELL_INDEX].Controls(YOUR_CONTROL_INDEX), TextBox).Text

YOUR_CELL_INDEX - which column. The index starts from 0.
YOUR_CONTROL_INDEX - control's index. Try 0.
sevengenn 14-Feb-11 22:06pm    
txtLName.Text = CType(GridView1.Rows[1].Cells[0].Controls(0), TextBox).Text

sir the 1 = tells that "identifier expected"

sir, I'm sorry for too many questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900