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

How to retrieve the selected row column value in RadGrid?

3 Answers 825 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ana
Top achievements
Rank 1
Ana asked on 20 Jun 2014, 12:33 AM
Hi,

I have nested RadGrid and I want to get the value of a particular column from the selected row of matertableview( in other words clicking on the expand/collapse). Because, I need to use that for the child items query.

Below is my code-snippet:

​protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
            // code???
                    string customerid= dataItem.GetDataKeyValue("CustomerId");
 }

Thanks a million.
           

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 20 Jun 2014, 05:28 AM
Hi Ana,

Please try the below C# code snippet to access the DataKeyValue of expanded row.

C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == "ExpandCollapse")
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        string customerid = dataItem.GetDataKeyValue("CustomerID").ToString();
    }
}

Thanks,
Shinu.
0
Ana
Top achievements
Rank 1
answered on 20 Jun 2014, 11:37 AM
Hi Shinu,

I couldn't get the value of string customerid.  It is still showing up as null. 
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 Jun 2014, 05:48 AM
Hi Ana,

I guess you have a hierarchy grid, please make sure you have set the DataKeyNames property in the aspx for the tables and try accessing them with the table name as shown below:

ASPX:
<MasterTableView DataKeyNames="CustomerID"  Name="Customers">

C#:
if (e.CommandName == "ExpandCollapse" && e.Item.OwnerTableView.Name == "Customers")
{
  GridDataItem dataItem = e.Item as GridDataItem;
  string customerid = dataItem.GetDataKeyValue("CustomerID").ToString();
}

Thanks,
Princy
Tags
General Discussions
Asked by
Ana
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ana
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or