当用户点击View链接时,我想将studentID从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>
答案 0 :(得分: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 ..
});
});
这是关于如何做到这一点的jsfiddle
答案 1 :(得分:2)
看起来您可能在这里使用网络表单 - 您是否尝试过使用隐藏字段?将锚标记click事件绑定到jQuery函数后:
啊,我看到GJohn打败了我 ...那么您应该能够在页面响应生命周期中引用该ID,例如int studentID = hfStudentID.Value;