?
Solved

gridview selected row

Posted on 2006-11-20
7
Medium Priority
?
6,688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 total points
ID: 17980859
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!

 
LVL 28

Accepted Solution

by:
strickdd earned 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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