asp.net實(shí)現(xiàn)批量刪除實(shí)例
本文實(shí)例講述了asp.net實(shí)現(xiàn)批量刪除功能的方法。對于asp.net的學(xué)習(xí)有一定的參考價值。分享給大家供大家參考之用。具體實(shí)現(xiàn)方法入戲:
.aspx文件代碼如下:
<asp:GridView ID="GridView1" runat="server" Width="100%" EmptyDataText="暫時無數(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="序號" >
<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ā)表時間">
<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ù)據(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é)有余力的朋友還可以對代碼作出改進(jìn)以完善其功能。希望本文實(shí)例對大家的asp.net學(xué)習(xí)有一定的幫助作用。
- asp.net下gridview 批量刪除的實(shí)現(xiàn)方法
- asp.net gridview多頁時的批量刪除
- Asp.Net 文件操作基類(讀取,刪除,批量拷貝,刪除,寫入,獲取文件夾大小,文件屬性,遍歷目錄)
- asp.net repeater實(shí)現(xiàn)批量刪除時注冊多選框id到客戶端
- asp.net repeater實(shí)現(xiàn)批量刪除
- JQuery實(shí)現(xiàn)Repeater無刷新批量刪除(附后臺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(c#)獲取內(nèi)容第一張圖片地址的函數(shù)
C#獲取文章類第一張圖片的地址的函數(shù)(留著以后用),先說一下思路2009-11-11
ASP.NET MVC 4使用PagedList.Mvc分頁的實(shí)現(xiàn)代碼
本篇文章主要介紹了ASP.NET MVC 4使用PagedList.Mvc分頁的實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
ASP.Net MVC+Data Table實(shí)現(xiàn)分頁+排序功能的方法
這篇文章主要介紹了ASP.Net MVC+Data Table實(shí)現(xiàn)分頁+排序功能的方法,結(jié)合實(shí)例形式分析了asp.net基于mvc架構(gòu)實(shí)現(xiàn)的數(shù)據(jù)查詢、排序、分頁顯示等相關(guān)操作技巧,需要的朋友可以參考下2017-06-06
.NET運(yùn)行界面上,實(shí)現(xiàn)隨意拖動控件的方法
.NET運(yùn)行界面上,實(shí)現(xiàn)隨意拖動控件的方法,需要的朋友可以參考一下2013-03-03
MVC文件上傳支持批量上傳拖拽及預(yù)覽文件內(nèi)容校驗(yàn)功能
這篇文章主要介紹了MVC文件上傳支持批量上傳拖拽及預(yù)覽文件內(nèi)容校驗(yàn)功能,需要的朋友可以參考下2017-03-03
ASP.NET 修復(fù) IIS 映射具體實(shí)現(xiàn)步驟
本文主要介紹IIS映射的具體步驟,希望對大家有所幫助。2016-05-05
.Net?ORM?訪問?Firebird?數(shù)據(jù)庫的方法
這篇文章簡單介紹了在?.net6.0?環(huán)境中使用?FreeSql?對?Firebird?數(shù)據(jù)庫的訪問,目前?FreeSql?還支持.net?framework?4.0?和?xamarin?平臺上使用,對.Net?ORM?訪問?Firebird?數(shù)據(jù)庫相關(guān)知識感興趣的朋友一起看看吧2022-07-07

