中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

GridView中怎么自定義刪除操作

發布時間:2021-07-27 15:27:04 來源:億速云 閱讀:149 作者:Leah 欄目:開發技術

本篇文章為大家展示了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" >
                            <tr>
                            <td >
                                第<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中怎么自定義刪除操作,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

达尔| 阿尔山市| 博乐市| 铜鼓县| 盱眙县| 昌黎县| 延长县| 什邡市| 浦城县| 桃园县| 永城市| 大化| 蒙山县| 榆树市| 马龙县| 太仆寺旗| 松溪县| 茂名市| 内乡县| 新龙县| 张掖市| 油尖旺区| 拜泉县| 苏州市| 黄石市| 驻马店市| 益阳市| 东安县| 会昌县| 团风县| 怀远县| 望都县| 晋州市| 双牌县| 江阴市| 榆林市| 封丘县| 南华县| 高平市| 元阳县| 鹤山市|