Solved

gridview selected row

Posted on 2006-11-20
7
6,667 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 17

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now