Solved

gridview selected row

Posted on 2006-11-20
7
6,673 Views
Last Modified: 2011-08-18
I am trying to get the id of the selected row in a gridview instead of the index

0
Comment
Question by:samme
7 Comments
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 17980633
GridView1.DataKeys[GridView1.SelectedRow.Index];
0
 
LVL 1

Author Comment

by:samme
ID: 17980696
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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 50 total points
ID: 17980859
GridView1.DataKeys(GridView1.SelectedIndex)

Bob
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 28

Accepted Solution

by:
strickdd earned 75 total points
ID: 17981994
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
 
LVL 4

Expert Comment

by:satish_nagdev
ID: 17985540
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
 
LVL 1

Author Comment

by:samme
ID: 17995592
Ended up with this result
Dim selectedRecord As DataKey = GridView1.DataKeys(GridView1.SelectedIndex)
Dim idValue As String = selectedRecord.Value
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17995608
And, does that work as expected?

Bob
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question