asp.net 不用GridView自帶刪除功能,刪除一行數(shù)據(jù)
<asp:GridView ID="GridLog" runat="server"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID"
BorderColor="#333" BorderStyle="solid" BorderWidth="1"
OnRowDeleting="PublicGridRowDeleting"
GridLines="None" Width="98%" ForeColor="#333333">
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="false"
ReadOnly="True"
SortExpression="ID" >
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:BoundField>
<asp:TemplateField HeaderText="刪除" ShowHeader="False">
<ItemStyle HorizontalAlign="Center" Width="40px" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('您確認(rèn)刪
除?');" Text="刪除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333"
/>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center"
/>
<HeaderStyle BackColor="#5A799C" ForeColor="White" Height="22px" />
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<EmptyDataTemplate>
日志庫(kù)暫時(shí)為空!
</EmptyDataTemplate>
</asp:GridView>
CS代碼
protected void PublicGridRowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strID = GridLog.DataKeys[e.RowIndex].Value.ToString();//strID就是該行的ID
string strSQL = "Delete from table " +
" WHERE id = " + strID;
//執(zhí)行刪除
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT
LANGUAGE='javascript'>alert('刪除成功!');</script>");
GridBind();
}
關(guān)鍵是設(shè)定好DataKeyNames后,可以靠 string strID = GridLog.DataKeys
[e.RowIndex].Value.ToString();獲得選擇列的ID值 然后用這個(gè)ID執(zhí)行刪除就可以了 。
- asp.net GridView控件中模板列CheckBox全選、反選、取消
- Asp.net GridView使用大全(分頁(yè)實(shí)現(xiàn))
- asp.net gridview代碼綁定
- asp.net GridView 刪除時(shí)彈出確認(rèn)對(duì)話框(包括內(nèi)容提示)
- asp.net Gridview里添加匯總行
- asp.net GridView排序簡(jiǎn)單實(shí)現(xiàn)
- asp.net DataGridView導(dǎo)出到Excel的三個(gè)方法[親測(cè)]
- asp.net中讓Repeater和GridView支持DataPager分頁(yè)
- asp.net 設(shè)置GridView的選中行
- asp.net gridview的Rowcommand命令中獲取行索引的方法總結(jié)
- asp.net實(shí)現(xiàn)固定GridView標(biāo)題欄的方法(凍結(jié)列功能)
相關(guān)文章
WPF實(shí)現(xiàn)簡(jiǎn)單的跑馬燈效果
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)簡(jiǎn)單的跑馬燈效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Visual Studio Debug實(shí)戰(zhàn)教程之?dāng)帱c(diǎn)操作
眾所周知斷點(diǎn)對(duì)于Visual Studio調(diào)試過(guò)程是十分重要的,斷點(diǎn)的設(shè)置也是為了更好的進(jìn)行調(diào)試。下面這篇文章主要給大家介紹了關(guān)于Visual Studio Debug實(shí)戰(zhàn)教程之?dāng)帱c(diǎn)操作的相關(guān)資料,需要的朋友可以參考下2018-09-09asp.net傳多個(gè)值到其它頁(yè)面的具體實(shí)現(xiàn)
在頁(yè)面之間的跳轉(zhuǎn),經(jīng)常會(huì)用到傳值,其中可能會(huì)傳遞多個(gè)值,下面為大家介紹下asp.net傳多個(gè)值到其它頁(yè)面的方法,需要的朋友可以參考下2014-02-02設(shè)置默認(rèn)Ajax操作cache and error
設(shè)置默認(rèn)Ajax操作cache and error,需要的朋友可以參考一下2013-02-02.NET?Core企業(yè)微信網(wǎng)頁(yè)授權(quán)登錄的實(shí)現(xiàn)
本文主要介紹了.NET?Core企業(yè)微信網(wǎng)頁(yè)授權(quán)登錄的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù)
由于項(xiàng)目中有許多頁(yè)面需要用到cid參數(shù),所以想通過(guò)傳值cid來(lái)獲取數(shù)據(jù)。2010-01-01asp.net 合并GridView中某列相同信息的行(單元格)
合并GridView中某列相同信息的行(單元格)2009-11-11效控制C#中l(wèi)abel輸出文字的長(zhǎng)度,自動(dòng)換行
效控制C#中l(wèi)abel輸出文字的長(zhǎng)度,自動(dòng)換行...2007-04-04