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

How to get the ID when I select a detail table row?

1 Answer 567 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dong
Top achievements
Rank 1
dong asked on 05 Jun 2014, 02:57 AM
I have two table,master and detail.
<script type="text/javascript">
var id = "";
var id2 = "";
function RadGrid1_RowClick(sender, eventArgs)
{
    id = eventArgs.getDataKeyValue("ID");
}

function RadGrid2_RowClick(sender, eventArgs)
{
    id2 = eventArgs.getDataKeyValue("DetailID");
}
</script>
I can get master table row ID normally,but detail table failed.Please help me.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Jun 2014, 05:16 AM
Hi Dong,

I'm not clear if you are using two radgrids or a Radgrid with hierarchy. In case you have two different RadGrids and you want to get the ID on row click try the below code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" >
    <MasterTableView ClientDataKeyNames="OrderID">      
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowClick="Grid1OnRowClick" />
    </ClientSettings>
</telerik:RadGrid>
<br />
<br />
<telerik:RadGrid ID="RadGrid2" runat="server" >
    <MasterTableView ClientDataKeyNames="CustomerID">     
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowClick="Grid2OnRowClick" />
    </ClientSettings>
</telerik:RadGrid>

JS:
<script type="text/javascript">
    function Grid1OnRowClick(sender, eventArgs) {
        alert(eventArgs.getDataKeyValue("OrderID"));
    }
    function Grid2OnRowClick(sender, eventArgs) {
        alert(eventArgs.getDataKeyValue("CustomerID"));
    }
</script>

In case if you are using a Hierarchy Grid, try the following code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" >
    <MasterTableView Name="State" ClientDataKeyNames="StateID">     
      <DetailTables>          
        <telerik:GridTableView  Name="District" ClientDataKeyNames="DistrictID">                      
        </telerik:GridTableView>
      </DetailTables>     
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowClick="OnRowClick" />
    </ClientSettings>
</telerik:RadGrid>

JS:
<script type="text/javascript">
 function OnRowClick(sender, eventArgs) {
     if (eventArgs.get_tableView().get_name() == "State")
         alert(eventArgs.getDataKeyValue("StateID"));
 
     else if (eventArgs.get_tableView().get_name() == "District")
         alert(eventArgs.getDataKeyValue("DistrictID"));
   }
</script>

Provide your code snippet if this doesn't help.
Thanks,
Princy
Tags
Grid
Asked by
dong
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or