我在Gridview中有一个ButtonField,我正在使用onRowCommand来触发操作。我需要一个确认框在onRowCommand事件中返回/跳过代码,如果用户单击“取消”
这是grid.aspx.cs
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string commandname = e.CommandName;
if (commandname.Equals("atender"))
{
// here there are the codes...I need a confirmation box here which skip these codes if the user click in cancel
}
} 这是我的网格视图中的asp
<asp:GridView ID="GridView1" runat="server" CellPadding="4"
BorderStyle="None" BorderWidth="0px" CellSpacing="1" Width="100%"
GridLines="Vertical" AllowPaging="True" onrowcommand="GridView1_RowCommand"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onpageindexchanging="GridView1_PageIndexChanging"
onrowdatabound="GridView1_RowDataBound" PageSize="5" HorizontalAlign=Left
>
<PagerStyle HorizontalAlign="Center" />
<RowStyle CssClass="tabela_texto2" HorizontalAlign="Center"
VerticalAlign="Middle" />
<AlternatingRowStyle CssClass="tabela_texto1" />
<Columns>
<asp:ButtonField Text="Status" CommandName="atender" ButtonType="Button" />
<asp:ButtonField Text="Ver no mapa" CommandName="ver" ButtonType="Button" />
</Columns>
</asp:GridView>发布于 2014-12-22 23:20:04
您应该使用Javascript或Jquery在浏览器(客户端)中获取控件,以使其:
1)给ButtonField添加一个ControlStyle-CssClass:
<asp:ButtonField ControlStyle-CssClass="botonTransaccional" Text="Status" CommandName="atender" ButtonType="Button" />2)从http://code.jquery.com/jquery-1.11.2.min.js下载JQuery库(单个JS文件)
3)将文件保存在应用程序的某个目录中(我的示例中的JS文件夹)
4)在添加jquery功能之后,在HTML中添加引用,以便在客户端控制事件(可以在HTML文档的头部添加)。
<script src="/js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".botonTransaccional").click(funtion(e) {
if (confirm("Are you sure?") == false)
{
e.preventDefault();
}
});
});
</script>
<br>e.PreventDefault()函数防止事件缺省控制,在按钮元素中,缺省值是提交给服务器的PostBack。
https://stackoverflow.com/questions/27604276
复制相似问题