RadGrid for ASP.NET

RadGrid Send comments on this topic.
SelectedValue Property
See Also  Example
Telerik.WebControls Namespace > RadGrid Class : SelectedValue Property


Gets the data key value of the selected row in a RadGrid control.   

 

Namespace: Telerik.WebControls
Assembly: RadGrid (in RadGrid.dll)

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property SelectedValue As Object
Visual Basic (Usage)Copy Code
Dim instance As RadGrid
Dim value As Object
 
value = instance.SelectedValue
C# 
public object SelectedValue {get;}

Return Value

The data key value of the selected row in a RadGrid control.

Example

The following code example demonstrates how to use the SelectedValue property to determine the data key value of the selected row in a RadGrid control.
Visual BasicCopy Code
<%@ Page Language="VB" %>

<%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>
<!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    ' Display the primary key value of the selected row.
    Label1.Text = "The primary key value of the selected row is " & _
      RadGrid1.SelectedValue.ToString() & "."

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>RadGrid SelectedValue Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <h3>
            RadGrid SelectedValue Example</h3>
        <asp:Label ID="Label1" ForeColor="Red" runat="server" />
        <rad:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1"
            OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"
            runat="server">
            <MasterTableView DataKeyNames="CustomerID">
                <Columns>
                    <rad:GridButtonColumn CommandName="Select" Text="Select" />
                </Columns>
            </MasterTableView>
        </rad:RadGrid>
        <!-- This example uses Microsoft SQL Server And connects -->
        <!-- To the Northwind sample database. Use an ASP.NET -->
        <!-- expression To retrieve the connection String value -->
        <!-- from the Web.config file. -->
        <asp:SqlDataSource ID="SqlDataSource1" SelectCommand="SELECT * FROM [Customers]"
            runat="server" ConnectionString="<<see cref="NorthwindConnectionString">$ ConnectionStrings</see>>" />
    
</body>
</html>
C#Copy Code
<%@ Page Language="C#" %>

<%@ Register Assembly=
"RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>
<!DOCTYPE html Public
"-//W3C//DTD XHTML 1.0 Transitional//EN"
   
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat=
"server">
protected void RadGrid1_SelectedIndexChanged(