Hi, I am doing my final year project in visual studio 2005, and I am using a datagridview to populate all record from a given table. Well I wanted to know if there is a some kind of way that when the user clicks on a specific record from the datagridview(a row for instance), the resulting detail of that latter is further listed down.

Is there any way to get the index of the select row or is there any event for such manupilations?

Thanks in advance for your help

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView1.RowCommand

        If e.CommandName = "YOURCOMMANDNAME" Then


            Label1.Text = GridView1.DataKeys(e.CommandArgument).Values

        End If


    End Sub

You will need to specify the datakey as your unquie ident column from the database. Also, make sure to give the button a command name so you can grab the event. You need also to make sure that you ge the DataKey because if you just returned e.CommandArgument, it would only give you the row number (for isntance, 0 or 2) but not the unique ident record from the database.

Thanks for reply erictenson. You are using a gridview while I am using a datagridview and there is no such handler and event as rowcommand and gridviewcommandeventargs. Nevertheless, I have been able to figure out something. Thanks again for your reply.

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView1.RowCommand

        If e.CommandName = "YOURCOMMANDNAME" Then


            Label1.Text = GridView1.DataKeys(e.CommandArgument).Values

        End If


    End Sub

You will need to specify the datakey as your unquie ident column from the database. Also, make sure to give the button a command name so you can grab the event. You need also to make sure that you ge the DataKey because if you just returned e.CommandArgument, it would only give you the row number (for isntance, 0 or 2) but not the unique ident record from the database.

Please mark as solved and give me some rep points :) I am glad you got it working!

commented: this for you :D +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.