asp.net實(shí)現(xiàn)批量刪除實(shí)例
本文實(shí)例講述了asp.net實(shí)現(xiàn)批量刪除功能的方法。對(duì)于asp.net的學(xué)習(xí)有一定的參考價(jià)值。分享給大家供大家參考之用。具體實(shí)現(xiàn)方法入戲:
.aspx文件代碼如下:
<asp:GridView ID="GridView1" runat="server" Width="100%" EmptyDataText="暫時(shí)無(wú)數(shù)據(jù)" BorderColor="White" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="選擇">
<ItemStyle Width="20px" />
<ItemTemplate>
<asp:CheckBox id="id" runat="Server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="序號(hào)" >
<ItemStyle Width="20px" />
</asp:BoundField>
<asp:TemplateField HeaderText="標(biāo)題">
<ItemStyle Width="400px" />
<ItemTemplate>
<a href="../shangpu/<%#eval_r("pageurl") %>" target="_blank"><%#eval_r("title") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="發(fā)表時(shí)間">
<ItemStyle Width="100px" />
<ItemTemplate>
<%# Convert.ToDateTime(eval_r("addtime")).Date.ToString("yyyy-MM-dd") %>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFormatString="shangpu_edit.aspx?id={0}" Text="修改" NavigateUrl="shangpu_edit.aspx?id={0}" DataNavigateUrlFields="id" >
<ItemStyle Width="30px" />
</asp:HyperLinkField>
<asp:CommandField ShowDeleteButton="True" HeaderText="刪除" DeleteText="<div id="de" onclick="JavaScript:return confirm('確定刪除嗎?')">刪除</div>" >
<ItemStyle Width="30px" />
</asp:CommandField>
</Columns>
<EmptyDataTemplate>
<font color=red>暫時(shí)無(wú)數(shù)據(jù)</font>
</EmptyDataTemplate>
<RowStyle Height="20px" />
</asp:GridView>
.cs 文件代碼如下:
protected void btndeleteall_Click(object sender, EventArgs e)
{
string sqltext = "(";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chb = (CheckBox)GridView1.Rows[i].FindControl("id");
if (chb.Checked)
{
sqltext = sqltext + GridView1.DataKeys[i].Value.ToString() + ",";
}
}
sqltext = sqltext.Substring(0, sqltext.Length - 1) + ")";
sqltext = "delete from shangpu where id in" + sqltext;
string sqlcon = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(sqlcon);
con.Open();
SqlCommand cmd = new SqlCommand(sqltext, con);
try
{
int count = Convert.ToInt32(cmd.ExecuteNonQuery());
if (count > 0)
{
viewbind();
MessageBox.Show(this, "刪除成功,共刪除" + count + "條記錄!");
}
}
catch
{
MessageBox.Show(this, "刪除失?。?);
}
finally
{
con.Close();
con.Dispose();
}
}
感興趣的朋友可以調(diào)試運(yùn)行一下本文實(shí)例,學(xué)有余力的朋友還可以對(duì)代碼作出改進(jìn)以完善其功能。希望本文實(shí)例對(duì)大家的asp.net學(xué)習(xí)有一定的幫助作用。
- asp.net下gridview 批量刪除的實(shí)現(xiàn)方法
- asp.net gridview多頁(yè)時(shí)的批量刪除
- Asp.Net 文件操作基類(讀取,刪除,批量拷貝,刪除,寫(xiě)入,獲取文件夾大小,文件屬性,遍歷目錄)
- asp.net repeater實(shí)現(xiàn)批量刪除時(shí)注冊(cè)多選框id到客戶端
- asp.net repeater實(shí)現(xiàn)批量刪除
- JQuery實(shí)現(xiàn)Repeater無(wú)刷新批量刪除(附后臺(tái)asp.net源碼)
- sql server中批量插入與更新兩種解決方案分享(asp.net)
- Asp.Net使用Bulk實(shí)現(xiàn)批量插入數(shù)據(jù)
- ASP.NET批量下載文件的方法
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十七:DataList批量更新
- 在ASP.NET 2.0中操作數(shù)據(jù)之六十二:GridView批量更新數(shù)據(jù)
- 在ASP.NET 2.0中操作數(shù)據(jù)之六十三:GridView實(shí)現(xiàn)批量刪除數(shù)據(jù)
- 在ASP.NET 2.0中操作數(shù)據(jù)之六十四:GridView批量添加數(shù)據(jù)
相關(guān)文章
asp.net System.Guid ToString五種格式
這篇文章主要介紹了asp.net System.Guid ToString五種格式,需要的朋友可以參考下2017-02-02
ASP.NET對(duì)IIS中的虛擬目錄進(jìn)行操作的代碼
在做系統(tǒng)開(kāi)發(fā)的過(guò)程中,我們經(jīng)常會(huì)遇到用asp.net來(lái)操作IIS,如新建虛擬目錄、更改虛擬目錄的屬性、刪除虛擬目錄等操作,現(xiàn)在分析如下2012-10-10
.net mvc頁(yè)面UI之Jquery博客日歷控件實(shí)現(xiàn)代碼
最近在做一個(gè)博客系統(tǒng),其他需要用到博客日歷控件,網(wǎng)上搜索了很多資料,其中大部分都是javascript的,經(jīng)過(guò)總結(jié)使用jquery實(shí)現(xiàn)了博客日歷效果。代碼如下2013-09-09
如何使用ASP.NET制作簡(jiǎn)單的驗(yàn)證碼
當(dāng)用戶進(jìn)行注冊(cè)、登陸的時(shí)候都會(huì)遇到輸入驗(yàn)證碼的情況,那驗(yàn)證碼到底是怎么產(chǎn)生的吶,本文就是介紹了如何使用ASP.NET制作簡(jiǎn)單的驗(yàn)證碼,感興趣的朋友可以參考一下2015-07-07
用Html5與Asp.net MVC上傳多個(gè)文件的實(shí)現(xiàn)代碼
Html 5 的有一些File API,對(duì)Form表單增強(qiáng)的特性,讓我們輕松支持多文件上傳,看下面的Html片斷代碼2012-08-08
.Net中異步任務(wù)的取消和監(jiān)控的具體實(shí)現(xiàn)
本文主要介紹了.Net中異步任務(wù)的取消和監(jiān)控的具體實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
ASP.NET簡(jiǎn)單實(shí)現(xiàn)注銷功能
這篇文章主要介紹了如何ASP.NET簡(jiǎn)單實(shí)現(xiàn)注銷功能的方法以及簡(jiǎn)單示例,有需要的小伙伴可以參考下。2015-07-07
.net core利用orm如何操作mysql數(shù)據(jù)庫(kù)詳解
這篇文章主要給大家介紹了關(guān)于.net core利用orm如何操作mysql數(shù)據(jù)庫(kù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05

