how to change the select button value to the row selected in Gridview

hi,

how do I change the select button value to the corresponding row/cell value in a Gridview

Thanks
Shiva_KumarAsked:
Who is Participating?
 
Shiva_KumarConnect With a Mentor Author Commented:
hi,

I have tried a different approach to change the select button text to match the row text.  I have added the following code to the RowDataBound
=========================================================================
Dim row As GridViewRow = e.Row
        Dim selectCell As TableCell = row.Cells(0)
        If (selectCell.Controls.Count > 0) Then

            Dim selectControl As LinkButton = selectCell.Controls(0)
            If Not IsDBNull(selectControl) Then

                selectControl.Text = e.Row.Cells(1).Text
              End If
        End If
==============================================================================
It is now showing the select box as the row text but it shows in this way

          <Row Name>
abc         abc
xyz         xyz
123         123

I have added the line
e.Row.Cells(1).Visible = False

to disable the second column... but it still shows the <Row Name> and the place holder for the second coumn still exists.

How can I remove the complete second row and have only select button column shown.  Please provide the steps with vb code(i am new to asp.net)

Thanks

0
 
prairiedogCommented:
Could you please elaborate your question a little more?
0
 
amar31282Commented:
please explain your question little more
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
bizjoshCommented:
You need to pass the cell value into the button's code parameter of value=''

Cheers.
0
 
Shiva_KumarAuthor Commented:
Hi bizjosh

Could you please explain me in detail how do i do this.

By default the button is a link and the default text it shows is "Select"

Thanks,
Shiva
0
 
prairiedogCommented:
The whole idea here is to first find the Select button, then you can change its Text property to whatever you wish.
0
 
Shiva_KumarAuthor Commented:
Ok... Let me explain what I am trying to here:

i have a gridview which populates on sigle column from the database like this.

abc
xyz
123

i wanted to have these values clickable so that i can populate another gridview next to it taking the SelectedIndexValue as one of the parameter to run another sql query to popluate the gridveiw2.

In order to achieve this i have added a commandfield select, so after adding this it shows something like this:

Select   abc
Select   xyz
Select   123

Now what i am to do is to have the "Select" to replace with the actual row values and the same time it should be clickable so that i can popluate the second gridview.

Please let me know if this is a wrong approach.  If yes, the please let me know is there any alternate way of doing this.

Thanks,
Shiva


0
 
prairiedogCommented:
The better way to do is define DataKeyNames="YourPrimaryKeyField", then in the SelectedRowIndexChanged event handler, get the primary key as follows to run another query:
Dim id As Integer
id = Integer.Parse(Me.GridView1.SelectedDataKey.Value.ToString())
Do you use VB or C#?
0
 
Shiva_KumarAuthor Commented:
I use VB
0
 
prairiedogCommented:
Can you try my comment then and let me know if it works for you?
0
 
Shiva_KumarAuthor Commented:
Nope, it didn't work for me.  

any alternate suggestion?
0
 
prairiedogCommented:
What do you mean "it didn't work"? You got an error?
0
 
Shiva_KumarAuthor Commented:
Hi,

i was able to fix the second issue by adding the headertext = "false" in the girdview property.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.