主頁 > 知識(shí)庫 > GridView自定義刪除操作的具體方法

GridView自定義刪除操作的具體方法

熱門標(biāo)簽:世紀(jì)佳緣地圖標(biāo)注怎么去掉 外呼系統(tǒng)費(fèi)用一年 巫師3為什么地圖標(biāo)注的財(cái)寶沒有 怎么給超市做地圖標(biāo)注入駐店 手機(jī)地圖標(biāo)注如何刪除 十堰正規(guī)電銷機(jī)器人系統(tǒng) 寧波自動(dòng)外呼系統(tǒng)代理 辦理400電話證件 外呼系統(tǒng)代理品牌

首先,我們前端的代碼如下:

復(fù)制代碼 代碼如下:

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="通知手機(jī)" SortExpression="P_tel" ItemStyle-HorizontalAlign="Center"  >
                                ItemStyle HorizontalAlign="Center">/ItemStyle>/asp:BoundField>
                                asp:BoundField DataField="P_jg" HeaderText="通知間隔(小時(shí))" 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="最后發(fā)送時(shí)間" 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>
                        沒有數(shù)據(jù)!
                        /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>

后端的話,由于需要彈出刪除前的確認(rèn)框,所以,我們需要在RowDataBound里面做點(diǎn)什么?同時(shí),要想真正的刪除,還需要觸發(fā)RowDeleting事件,具體代碼如下:

復(fù)制代碼 代碼如下:

//報(bào)警刪除
        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('你確認(rèn)要?jiǎng)h除?')) javascript:__doPostBack('gridViewDxjk','Delete$" + e.Row.RowIndex.ToString() + "'); else return false;";
            }
        }

您可能感興趣的文章:
  • GridView分頁的實(shí)現(xiàn)以及自定義分頁樣式功能實(shí)例
  • GridView自定義分頁的四種存儲(chǔ)過程
  • C#自定義DataGridViewColumn顯示TreeView
  • yii2.0之GridView自定義按鈕和鏈接用法
  • 自定義GridView并且實(shí)現(xiàn)拖拽(附源碼)
  • asp.net gridview自定義value值的代碼
  • asp.net gridview分頁:第一頁 下一頁 1 2 3 4 上一頁 最末頁
  • asp.net中的GridView分頁問題
  • Android入門之ActivityGroup+GridView實(shí)現(xiàn)Tab分頁標(biāo)簽的方法
  • asp.net Gridview分頁保存選項(xiàng)
  • 基于GridView和ActivityGroup實(shí)現(xiàn)的TAB分頁(附源碼)
  • GridView自定義分頁實(shí)例詳解(附demo源碼下載)

標(biāo)簽:泰州 牡丹江 天門 景德鎮(zhèn) 山西 通遼 嘉興

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《GridView自定義刪除操作的具體方法》,本文關(guān)鍵詞  GridView,自定義,刪除,操作,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《GridView自定義刪除操作的具體方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于GridView自定義刪除操作的具體方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章