Thursday, January 24, 2013

Accessing DataKeys in Telerik RadGrid

Let's assume that we have a RadGrid with a bind DataTable which contains the columns "ConnectionString" and "HDSite". To add the Column names to the Datakeys we can use a code something like below.

<telerik:RadGrid ID="gridSearchL3" runat="server" >
<mastertableview DataKeyNames="ConnectionString,HDSite">
<telerik:GridButtonColumn CommandName="Select" Text="View" UniqueName="LinkColumn" ItemStyle-Width="40" HeaderStyle-Width="40">

To access the DataKeys of each record use the below code.

foreach (GridDataItem item in gridSearchL3.MasterTableView.Items)
string conStr = item.GetDataKeyValue("ConnectionString").ToString();
string HSite = item.GetDataKeyValue("HDSite").ToString();

No comments:
Write comments
Recommended Posts × +