0

我在行双击时使用以下代码获取数据键值,现在我想在服务器端使用这个键值,我怎样才能在那里获得这个值(或)如何将这个值传递给服务器端?

<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> 
4

3 回答 3

1

终于我得到了这个问题的答案,下面是答案

   <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.
    }
于 2013-10-28T11:40:06.673 回答
0

您可以使用以下代码在客户端获取数据键值:

function OnRowDblClick(sender, args) {

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

    } 

要将这些值传递给服务器端,一个建议是您可以将其分配给隐藏字段并在服务器端访问该隐藏字段。

于 2013-10-28T04:55:48.743 回答
0

这里可能会解决您的问题 http://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx

于 2013-10-26T09:06:51.453 回答