• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6704
  • Last Modified:

gridview selected row

I am trying to get the id of the selected row in a gridview instead of the index

0
samme
Asked:
samme
2 Solutions
 
Elvio Lujan.Net Senior DeveloperCommented:
GridView1.DataKeys[GridView1.SelectedRow.Index];
0
 
sammeAuthor Commented:
I am using vb so i changed it to
GridView1.DataKeys(GridView1.SelectedRow.Index)

It gives me the error "index not a member of system....gridviewrow"
0
 
Bob LearnedCommented:
GridView1.DataKeys(GridView1.SelectedIndex)

Bob
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
strickddCommented:
I did my best to convert my C# to VB, but just in case I have both...

protected Sub GridView_RowCommand(object sender, GridViewCommandEventArgs e)

            'find out which row was clicked
            Dim rowIndex as Int = e.CommandArgument;

            dim DBID as Int = sender.DataKeys(rowIndex).Value;

End Sub

protected void CategoryDataGrid_RowCommand(object sender, GridViewCommandEventArgs e)
      {
            // find out which row was clicked
            int rowIndex = Utilities.CommonFunctions.ConvertToInt(e.CommandArgument);

            String DBID = Utilities.CommonFunctions.ConvertToString(((GridView)sender).DataKeys[rowIndex].Value);
      }
0
 
satish_nagdevCommented:
hi,
could you try this
    protected void gv1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
    {
        int indx = e.NewSelectedIndex;
       //then you can access new selected row & its cells using
       //gv1.Rows[indx].Cells
    }

regards,
satish.
0
 
sammeAuthor Commented:
Ended up with this result
Dim selectedRecord As DataKey = GridView1.DataKeys(GridView1.SelectedIndex)
Dim idValue As String = selectedRecord.Value
0
 
Bob LearnedCommented:
And, does that work as expected?

Bob
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now