首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GridView confirm命令确认框

GridView confirm命令确认框
EN

Stack Overflow用户
提问于 2014-12-22 22:06:29
回答 1查看 111关注 0票数 0

我在Gridview中有一个ButtonField,我正在使用onRowCommand来触发操作。我需要一个确认框在onRowCommand事件中返回/跳过代码,如果用户单击“取消”

这是grid.aspx.cs

代码语言:javascript
复制
  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

代码语言:javascript
复制
          <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>
EN

回答 1

Stack Overflow用户

发布于 2014-12-22 23:20:04

您应该使用Javascript或Jquery在浏览器(客户端)中获取控件,以使其:

1)给ButtonField添加一个ControlStyle-CssClass:

代码语言:javascript
复制
<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文档的头部添加)。

代码语言:javascript
复制
   <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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27604276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档