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="通知手機(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>頁
<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事件,具體代碼如下:
//報(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源碼下載)
相關(guān)文章
Asp.net 頁面調(diào)用javascript變量的值
開發(fā)過程中碰到了這種情況,我想將javascript中定義的變量賦值給頁面中的TextBox控件.2009-12-12Visual?Studio創(chuàng)建WPF項(xiàng)目
這篇文章介紹了使用Visual?Studio創(chuàng)建WPF項(xiàng)目的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04ASP.NET Core中間件會(huì)話狀態(tài)讀寫及生命周期示例
這篇文章主要為大家介紹了ASP.NET Core中間件會(huì)話狀態(tài)讀寫及生命周期示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04asp.net sql 數(shù)據(jù)庫處理函數(shù)命令
asp.net sql 數(shù)據(jù)庫處理函數(shù)命令 ,需要的朋友可以參考下。2009-10-10