2015-12-11 46 views
3

当用户点击View链接时,我想将jQuery代码中的studentID传递给C#代码函数,请指教。将jQuery网格值传递给c#

$(document).on("ready", function() { 
     obj = { 
      width: 940, 
      height: 555, 
      title: "Students List ", 
     }; 
     obj.colModel = [ 
          { 
          dataIndx: 7, editable: false, sortable: false, title: "Password", width: 65, align: "center", resizable: false, dataIndx: "studentID", 
          render: function (ui) 
          { 
           var rowData = ui.rowData, dataIndx = ui.dataIndx; 
           var val = rowData[dataIndx]; 

           return "<a href='#" + rowData.studentID + "' style='text-decoration: underline;'>View</a>"; 

          }, className: "checkboxColumn" 
          }, 
          { title: "Student Name", width: 220, getEditCellData: saveCell, dataIndx: "studentName" }, 
          { title: "Student ID", width: 120, getEditCellData: saveCell, dataIndx: "studentID" }, 
         ]; 

     obj.dataModel = { 
      dataType: "JSON", 
      rPP: 20, 
      sortDir: "down", 
      rPPOptions: [1, 10, 20, 30, 40, 50, 100, 500, 1000], 
      filterIndx: "", 
      filterValue: "" 
     }; 

     }); 

</script> 

电网

<asp:Content ID="Content2" ContentPlaceHolderID="PageTitlePlaceHolder" runat="server"> 
</asp:Content> 
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder" runat="server"> 
    <div id="grid_table" style="margin: auto;"></div> 

</asp:Content> 

回答

3

建议改变你的锚标记,这

<a href="javascript:void(0);" data-studentId=rowdata.studentID style='text-decoration: underline;' class='viewStudent' >View</a> 

那丝了点击事件jQuery中的视图按钮

$(document).ready(function() { 
     $(".viewStudent").on("click", function() { 
      .. do what you need to do here .. 
     }); 
}); 

这里是如何做到这一点

https://jsfiddle.net/8brpuo82/7/

+0

我可能会做错事。我试过这样的代码(返回“”;)。之后,我用警报的jQuery代码,但没有发生任何事情。请指教。 – Paul

+0

哦,我的坏让我编辑我的答案 – Gjohn

+0

对不起,如果我做错了什么,但请看下面的代码,没有运气:$(document).ready(function(){(“。viewStudent”)。 (“click”,function(){alert(“Record Selected ...”); }); }); – Paul

2

看起来你可以在这里使用web表单一的jsfiddle - 你尝试使用隐藏域?一旦你的锚标记点击事件绑定到jQuery函数:

啊,我看GJohn打我给它

...那么你应该能够引用页面响应生命周期内的ID,例如, int studentID = hfStudentID.Value;