佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > asp.net實(shí)現(xiàn)批量刪除實(shí)例

asp.net實(shí)現(xiàn)批量刪除實(shí)例

熱門標(biāo)簽:國(guó)美全國(guó)運(yùn)營(yíng)中心 電銷業(yè)務(wù) 網(wǎng)站排名優(yōu)化 客戶服務(wù) 百度AI接口 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 人工智能 電商新玩法

本文實(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 文件操作基類(讀取,刪除,批量拷貝,刪除,寫入,獲取文件夾大小,文件屬性,遍歷目錄)
  • 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ù)

標(biāo)簽:攀枝花 南平 棗莊 咸寧 拉薩 廈門 益陽(yáng) POS機(jī)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net實(shí)現(xiàn)批量刪除實(shí)例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    左贡县| 太和县| 西青区| 长寿区| 桑日县| 东城区| 尖扎县| 普定县| 汾西县| 三穗县| 鄱阳县| 棋牌| 长汀县| 纳雍县| 额尔古纳市| 荔波县| 德昌县| 察哈| 宁蒗| 许昌县| 新源县| 阳曲县| 密云县| 财经| 尖扎县| 民乐县| 从化市| 阳曲县| 塘沽区| 南涧| 尖扎县| 巴塘县| 政和县| 潜山县| 石门县| 红桥区| 武隆县| 迁安市| 青田县| 丹巴县| 化德县|