• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    GridView自定义删除操作的具体方法

    首先,我们前端的代码如下:

    复制代码 代码如下:

    asp:GridView ID="gridViewDxjk" CssClass="gridview" runat="server" AllowPaging="True"
                      DataKeyNames="P_ID" AutoGenerateColumns="False" 
                          RowStyle-HorizontalAlign="Center" BorderWidth="1px" PageSize="17"
                          onrowdeleting="gridViewDxjk_RowDeleting"
                          OnRowDataBound="gridViewDxjk_RowDataBound"
                          onpageindexchanging="gridViewDxjk_PageIndexChanging" >
                            HeaderStyle CssClass="head" />
                            PagerStyle CssClass="pager" />
                            RowStyle CssClass="row" />
                            EditRowStyle CssClass="editrow" />
                            AlternatingRowStyle CssClass="altrow" />
                            EmptyDataRowStyle CssClass="empty" />
                            Columns>                           
                             asp:HyperLinkField HeaderText="编辑" ControlStyle-Width="50" DataNavigateUrlFields="P_ID" DataNavigateUrlFormatString="smsModify.aspx?id={0}" Text="编辑"  >
                                    ControlStyle Width="50px">/ControlStyle>/asp:HyperLinkField>
                                    asp:CommandField  ShowDeleteButton="true" DeleteText="删除"   >
                                    ControlStyle Width="50px">/ControlStyle>/asp:CommandField>
                                    asp:BoundField DataField="P_ID" HeaderText="id" SortExpression="P_ID" ItemStyle-HorizontalAlign="Center"  Visible="False" >
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                    asp:BoundField DataField="P_NAME" HeaderText="名称" SortExpression="P_NAME" />
                                    asp:BoundField DataField="P_Type" HeaderText="通知方式" SortExpression="P_Type" ItemStyle-HorizontalAlign="Center"  >
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                    asp:BoundField DataField="P_Fzr" HeaderText="姓名" SortExpression="P_Fzr" ItemStyle-HorizontalAlign="Center"  >
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                    asp:BoundField DataField="P_tel" HeaderText="通知手机" SortExpression="P_tel" ItemStyle-HorizontalAlign="Center"  >
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                    asp:BoundField DataField="P_jg" HeaderText="通知间隔(小时)" SortExpression="P_jg" ItemStyle-HorizontalAlign="Center"  >
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                    asp:BoundField DataField="P_on" HeaderText="是否开启" SortExpression="P_on" ItemStyle-HorizontalAlign="Center"  >
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                    asp:BoundField DataField="P_lasttime" HeaderText="最后发送时间" SortExpression="P_lasttime" ItemStyle-HorizontalAlign="Center"  >
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                    asp:BoundField DataField="P_memo" HeaderText="备注" SortExpression="P_memo" ItemStyle-HorizontalAlign="Center"  >                  
                                    ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                            /Columns>
                            EmptyDataTemplate>
                            没有数据!
                            /EmptyDataTemplate>
                             PagerTemplate>
                            table width="100%" class="gvPage" style="font-size:12px;">
                                tr>
                                td style="text-align: right">
                                    第asp:Label ID="lblPageIndex" runat="server" Text='%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>'>/asp:Label>页
                                    /共asp:Label ID="lblPageCount" runat="server" Text='%# ((GridView)Container.Parent.Parent).PageCount %>'>/asp:Label>页nbsp;nbsp;
                                  asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Visible="%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页/asp:LinkButton>
                                  asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"  Visible="%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页/asp:LinkButton>
                                  asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"  Visible="%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页/asp:LinkButton>
                                  asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"  Visible="%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页/asp:LinkButton>
                                  asp:TextBox ID="txtNewPageIndex" runat="server" Text='%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>'  Width="20px" AutoPostBack="true" >/asp:TextBox>
                                  asp:LinkButton ID="btnGoEx" runat="server" CommandArgument="GO" CommandName="Page" Text="GO" OnClick="btnGoEx_Click">/asp:LinkButton>
                                /td>
                                /tr>
                            /table>
                        /PagerTemplate>
                     /asp:GridView>

    后端的话,由于需要弹出删除前的确认框,所以,我们需要在RowDataBound里面做点什么?同时,要想真正的删除,还需要触发RowDeleting事件,具体代码如下:

    复制代码 代码如下:

    //报警删除
            protected void gridViewDxjk_RowDeleting(object sender, GridViewDeleteEventArgs e)
            {
                string key = gridViewDxjk.DataKeys[e.RowIndex].Value.ToString();
                bool flag = bll.Delete(Int32.Parse(key));
                if (flag)
                    NXT_WLService.App_Code.JScript.Alert("删除成功!", this);
                else
                    NXT_WLService.App_Code.JScript.Alert("删除失败!", this);
            }

           
            protected void gridViewDxjk_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    LinkButton btn = (LinkButton)e.Row.Cells[1].Controls[0];
                    if (btn.Text.Equals("删除"))//刪除鈕才加提示訊息 
                        btn.OnClientClick = "if (confirm('你确认要删除?')) javascript:__doPostBack('gridViewDxjk','Delete$" + e.Row.RowIndex.ToString() + "'); else return false;";
                }
            }

    您可能感兴趣的文章:
    • GridView分页的实现以及自定义分页样式功能实例
    • GridView自定义分页的四种存储过程
    • C#自定义DataGridViewColumn显示TreeView
    • yii2.0之GridView自定义按钮和链接用法
    • 自定义GridView并且实现拖拽(附源码)
    • asp.net gridview自定义value值的代码
    • asp.net gridview分页:第一页 下一页 1 2 3 4 上一页 最末页
    • asp.net中的GridView分页问题
    • Android入门之ActivityGroup+GridView实现Tab分页标签的方法
    • asp.net Gridview分页保存选项
    • 基于GridView和ActivityGroup实现的TAB分页(附源码)
    • GridView自定义分页实例详解(附demo源码下载)
    上一篇:asp.net Textbox服务器控件
    下一篇:IE下document.referrer 拒绝访问的解决方法
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    GridView自定义删除操作的具体方法 GridView,自定义,删除,操作,