This is a migrated thread and some comments may be shown as answers.

[Solved] What is the RadGrid equivalent of GridView1.SelectedDataKey.Value

2 Answers 285 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan Schmecker
Top achievements
Rank 1
Dan Schmecker asked on 07 Jan 2010, 08:05 PM
What would be the RadGrid equivalent of the regular GridView Control's GridView1.SelectedDataKey.Value ???
Thanks.

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 08 Jan 2010, 07:09 AM
Hello Dan,

In RadGrid you can use

RadGrid1.SelectedValue or RadGrid1.SelectedValues



Best wishes,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Shinu
Top achievements
Rank 2
answered on 08 Jan 2010, 07:14 AM
Hello Dan Schmecker,

You can also use GetDataKeyValue() method in order to get the DataKeyValues from the owner GridTableView with the corresponding item ItemIndex and keyName. Here is the example.

aspx:
 
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" 
    AutoGenerateColumns="false" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
 
    <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="CustomerID"
        <Columns> 
          . . . 
        </Columns> 
    </MasterTableView> 
 
</telerik:RadGrid> 

cs:
 
string keyvalue = (RadGrid1.SelectedItems[0] as GridDataItem).GetDataKeyValue("CustomerID").ToString(); 
This returns the key value of first item in SelectedItemCollection.

Regards,
Shinu.
Tags
Grid
Asked by
Dan Schmecker
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or