Hi mahjoubi,
To get the selected row you need use GridView Rows by RowIndex with the help of SelectedIndex property.
Check below code.
HTML
<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnGet" Text="Get" runat="server" OnClick="OnGet" />
<hr />
Name:
<asp:Label ID="lblName" runat="server" /><br />
Country:
<asp:Label ID="lblCountry" runat="server" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=GridView1] td").hover(function () {
$("td", $(this).closest("tr")).addClass("hover_row");
}, function () {
$("td", $(this).closest("tr")).removeClass("hover_row");
});
});
</script>
Code
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn(2) {
New System.Data.DataColumn("Id"),
New System.Data.DataColumn("Name"),
New System.Data.DataColumn("Country")})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("onclick") = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" & e.Row.RowIndex)
e.Row.ToolTip = "Click to select this row."
End If
End Sub
Protected Sub OnGet(sender As Object, e As EventArgs)
Dim row As GridViewRow = GridView1.Rows(GridView1.SelectedIndex)
lblName.Text = row.Cells(0).Text.Trim()
lblCountry.Text = row.Cells(1).Text.Trim()
End Sub
Screenshot