我遇到了一个Jquery点击功能和使用gridview rowdatabound事件添加的javascript onclick功能的问题。第一次加载页面时,jquery点击功能正常工作。但是当单击GridView Row并触发javascript onclick函数时,jquery click函数不再起作用,我收到以下错误:
"输入字符串的格式不正确"。
这是脚本代码,我遇到了$(' .guardar')点击功能的问题。
<script>
function cargartabla() {
$('#MainContent_GVTrabajadores').DataTable({
"aaSorting": [],
responsive: true,
aLengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, "Todo"]
],
destroy: true,
});
}
$(document).ready(function() {
cargartabla();
var oTable;
$('.guardar').click(function () {
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = -1;
oTable.fnDraw();
});
oTable = $('#MainContent_GVTrabajadores').dataTable();
});
//On UpdatePanel Refresh
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
cargartabla();
var oTable;
$('.guardar').click(function () {
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = -1;
oTable.fnDraw();
});
oTable = $('#MainContent_GVTrabajadores').dataTable();
}
});
};
</script>
这是使用OnRowDataBound事件处理程序添加的行单击事件。
protected void GVTrabajadores_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GVTrabajadores, "Select$" + e.Row.RowIndex);
e.Row.Attributes["style"] = "cursor:pointer";
}
}