当行双击radgrid时如何获取datakey值

时间:2013-10-26 09:04:44

标签: c# javascript asp.net telerik

我正在使用以下代码在行双击时获取datakey值,现在我想在服务器端使用此键值,如何在那里获取此值(或)如何将此值传递给服务器端?

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> 
    <script type="text/javascript"> 
        function RadGrid1_RowDblClick(sender, args) {                    
            var keyValue = dataItem.getDataKeyValue('WageID'); 
            // want to get this keyvalue in server side 
        } 
    </script> 
</telerik:RadScriptBlock> 

<telerik:RadGrid ID="RadGrid1" runat="server" 
    OnNeedDataSource="RadGrid1_NeedDataSource"> 
    <MasterTableView ClientDataKeyNames="ID"> 
    </MasterTableView> 
    <ClientSettings> 
        <ClientEvents OnRowDblClick="RadGrid1_RowDblClick" /> 
    </ClientSettings>                
</telerik:RadGrid> 

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

您可以使用以下代码在客户端获取datakeyvalue:

function OnRowDblClick(sender, args) {

         var key=  args.getDataKeyValue("WageID");
   document.getElementById('<%= HidenField1.ClientID %>').value = key;

    } 

要将这些值传递给服务器端,您可以将其分配给 hiddenfield 并访问服务器端的隐藏字段。

答案 2 :(得分:0)

最后我得到了这个问题的答案,以下是答案

   <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> 
<script type="text/javascript"> 
    function RadGrid1_RowDblClick(sender, args) { 
    //changed code here 
      var grid = $find("<%= RadGrid1.ClientID %>");
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
            var key = MasterTable.getCellByColumnUniqueName(row, "WageID");  // get the value by uniquecolumnname
            var ID = key.innerHTML;        
            MasterTable.fireCommand("MyClick2",ID);        
     } 
</script> 
</telerik:RadScriptBlock> 

<telerik:RadGrid ID="RadGrid1" runat="server" 
OnNeedDataSource="RadGrid1_NeedDataSource"> 
<MasterTableView ClientDataKeyNames="ID"> 
</MasterTableView> 
<ClientSettings> 
    <ClientEvents OnRowDblClick="RadGrid1_RowDblClick" /> 
</ClientSettings>                
</telerik:RadGrid>

//在radgrid的itemcommand事件下添加此代码。

if (e.CommandName == "MyClick2")
    {
        object obj = e.CommandArgument;
        string ID = obj.ToString();
        //logic to fulfill our requirment.
    }