您好,是否可以使用 jQuery 获取 gridview 的当前行索引?
一点背景:
我使用模板字段中的服务器端链接按钮从 gridview 中删除行,如下所示:
<asp:LinkButton CausesValidation="false" CommandName="Delete" ID="lnkDelete"
OnClientClick="javascript: return(confirm('Delete item?'));" runat="server" Text="Delete" />
提示用户确认或取消删除。如果用户单击“确定”,则会在隐藏代码上调用此方法:
protected void GridViewRowDeleting(object sender, GridViewDeleteEventArgs e)
{
this.gridview_uploads.EditIndex = -1;
if (!this.UploadsList.Count.Equals(0))
{
DocumentUpload upload = this.UploadsList[e.RowIndex];
if (upload != null)
{
this.UploadsList.RemoveAt(e.RowIndex);
this.BindInputGridview();
}
}
}
但是 javascript 确认(删除项目?)看起来有点无趣。
我更喜欢使用类似 JQuery 对话框的东西,但如果我这样做,我不知道如何使用这种方法获取行索引(我可以弄清楚如何调用服务器代码)。
有任何想法吗?
很抱歉,如果已经有人问过这个问题了——我做了一些搜索,并用谷歌搜索了它,但找不到任何有用的东西。
If the LinkButton
是 GridView 中唯一的 LinkButton/Anchor,那么您应该能够执行类似的操作
$('#GridView1 a').click(function(){
return confirm("Delete Item");
});
编辑:将 #GridView1 更改为控件的 .net ID。
vb
<%=(me.GridView1.ClientID)%>
c#
<%=(this.GridView1.ClientID)%>
回复 阿德里亚诺斯
如果你调查jQuery UI 对话框 http://jqueryui.com/demos/dialog/,这有一个很好的模态确认框。
与上面的代码类似,但替换确认函数,您可以:
<script type="text/javascript">
$().ready(function(){
$( "#dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
autoOpen: false;
buttons: {
"Delete item": function() {
$( this ).dialog( "close" );
// Put in your return true/false here to activate button
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$('#GridView1 a').click(function(){
$('#dialog-confirm').dialog("open");
return false;
});
)};
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)