How to retrieve the selected row column value in RadGrid?

4 posts, 2 answers
  1. Ana
    Ana avatar
    12 posts
    Member since:
    Apr 2014

    Posted 19 Jun 2014 Link to this post

    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.
               
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Jun 2014 in reply to Ana Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ana
    Ana avatar
    12 posts
    Member since:
    Apr 2014

    Posted 20 Jun 2014 in reply to Shinu Link to this post

    Hi Shinu,

    I couldn't get the value of string customerid.  It is still showing up as null. 
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Jun 2014 in reply to Ana Link to this post

    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
Back to Top