无为清净楼资源网 Design By www.qnjia.com

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

复制代码 代码如下:
<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,自定义,删除

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。