digitalZo
asked on
Gridview Row Click Retrieve data
I have a Gridview with data. What I want to do is that when I click on a row, it should retrieve the whole row's data and bind it to the textboxes given.
I have tried this code:
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim gr As GridViewRow
For Each gr In GridView1.Rows
Dim tc As TableCell
For Each tc In gr.Cells
tc.Attributes.Add("onclick ", String.Format("document.ge tElementBy Id('Textbo x1').value = '{0}'", tc.Text))
Next tc
Next gr
End Sub 'GridView1_Load
. . but it works for only one textbox and one column click. I don't want that. I want that on click of a row, the whole row's data should be binded to the appropriate textboxes and dropdown.
2) Two columns retrieve their data from dropdowns. When I click on the row, the dropdowns should automatically change their selectedvalue as in the grid.
I would appreciate any help on this.
Thanks in advance.
I have tried this code:
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim gr As GridViewRow
For Each gr In GridView1.Rows
Dim tc As TableCell
For Each tc In gr.Cells
tc.Attributes.Add("onclick
Next tc
Next gr
End Sub 'GridView1_Load
. . but it works for only one textbox and one column click. I don't want that. I want that on click of a row, the whole row's data should be binded to the appropriate textboxes and dropdown.
2) Two columns retrieve their data from dropdowns. When I click on the row, the dropdowns should automatically change their selectedvalue as in the grid.
I would appreciate any help on this.
Thanks in advance.
ASKER
Thanks for the quick response but it doesn't work. It doesn't do anything on row click.
I'll have to define the textboxes too somewhere to bind the data to it.
I'll have to define the textboxes too somewhere to bind the data to it.
you are basically applying the onClick event to TableCell and you are checking on row click? Then how is it going to get fired.
ASKER
<<you are basically applying the onClick event to TableCell and you are checking on row click? Then how is it going to get fired.>>
Am I? What is the correct solution then?
I want to click on the row and as soon as I click on it, the data of that particular row should get binded to the textboxes or dropdowns.
Am I? What is the correct solution then?
I want to click on the row and as soon as I click on it, the data of that particular row should get binded to the textboxes or dropdowns.
ASKER
<<you are basically applying the onClick event to TableCell and you are checking on row click? Then how is it going to get fired.>>
Sorry. i didn't understand what you meant at first.
i did try clicking on table cell, but it doesn't work either way. i've tried such a code and i dont want it that way. i dont want to click on each table cell for it to bind to the textboxes.
i just want to click on the row anywhere, and the relevant data should bind to the appropriate textboxes or dropdowns.
Sorry. i didn't understand what you meant at first.
i did try clicking on table cell, but it doesn't work either way. i've tried such a code and i dont want it that way. i dont want to click on each table cell for it to bind to the textboxes.
i just want to click on the row anywhere, and the relevant data should bind to the appropriate textboxes or dropdowns.
Can you say me what are the names of text boxes in the rows look like?
ASKER
I've posted a code in my opening post:
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim gr As GridViewRow
For Each gr In GridView1.Rows
Dim tc As TableCell
For Each tc In gr.Cells
tc.Attributes.Add("onclick ", String.Format("document.ge tElementBy Id('Textbo x1').value = '{0}'", tc.Text))
Next tc
Next gr
End Sub 'GridView1_Load
the textbox names could be textbox1, textbox2, textbox3, and so on. The thing is, I want to know how to bind the row's data to the textboxes and dropdowns.
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim gr As GridViewRow
For Each gr In GridView1.Rows
Dim tc As TableCell
For Each tc In gr.Cells
tc.Attributes.Add("onclick
Next tc
Next gr
End Sub 'GridView1_Load
the textbox names could be textbox1, textbox2, textbox3, and so on. The thing is, I want to know how to bind the row's data to the textboxes and dropdowns.
ASKER
. . on row click.
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim cnt as Interger = 1
Dim gr As GridViewRow
For Each gr In GridView1.Rows
gr.Attributes.Add("onclick ", "document.getElementById(' Textbox" & cnt & "').value = document.getElementById('T extbox" & cnt & "').text;")
cnt += 1
Next gr
End Sub 'GridView1_Load
Dim cnt as Interger = 1
Dim gr As GridViewRow
For Each gr In GridView1.Rows
gr.Attributes.Add("onclick
cnt += 1
Next gr
End Sub 'GridView1_Load
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry a typo:
with the clicked row's data*.
with the clicked row's data*.
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
Dim gr As GridViewRow
For Each gr In GridView1.Rows
Dim tc As TableCell
For Each tc In gr.Cells
tc.Attributes.Add("onclick
Next tc
Next gr
End Sub 'GridView1_Load