濮阳杆衣贸易有限公司

主頁 > 知識庫 > asp.net實現(xiàn)批量刪除實例

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

熱門標簽:柳州電銷機器人公司 昆明語音電銷機器人價格 400電話如何申請取消 太原400電話上門辦理 電銷語音機器人型號參數(shù) 百度地圖怎樣做地圖標注 征途美甲店地圖標注 騰訊地圖標注手機 浦發(fā)電話機器人提醒還款

本文實例講述了asp.net實現(xiàn)批量刪除功能的方法。對于asp.net的學習有一定的參考價值。分享給大家供大家參考之用。具體實現(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="標題">
 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)試運行一下本文實例,學有余力的朋友還可以對代碼作出改進以完善其功能。希望本文實例對大家的asp.net學習有一定的幫助作用。

您可能感興趣的文章:
  • asp.net下gridview 批量刪除的實現(xiàn)方法
  • asp.net gridview多頁時的批量刪除
  • Asp.Net 文件操作基類(讀取,刪除,批量拷貝,刪除,寫入,獲取文件夾大小,文件屬性,遍歷目錄)
  • asp.net repeater實現(xiàn)批量刪除時注冊多選框id到客戶端
  • asp.net repeater實現(xiàn)批量刪除
  • JQuery實現(xiàn)Repeater無刷新批量刪除(附后臺asp.net源碼)
  • sql server中批量插入與更新兩種解決方案分享(asp.net)
  • Asp.Net使用Bulk實現(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實現(xiàn)批量刪除數(shù)據(jù)
  • 在ASP.NET 2.0中操作數(shù)據(jù)之六十四:GridView批量添加數(shù)據(jù)

標簽:江蘇 新疆 蘭州 陽泉 德陽 張家界 天門 白山

巨人網(wǎng)絡通訊聲明:本文標題《asp.net實現(xiàn)批量刪除實例》,本文關(guān)鍵詞  asp.net,實現(xiàn),批量,刪除,實例,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net實現(xiàn)批量刪除實例》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net實現(xiàn)批量刪除實例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    昆山市| 苏尼特右旗| 英吉沙县| 浦东新区| 东乌珠穆沁旗| 磐安县| 江阴市| 突泉县| 比如县| 桐乡市| 花莲市| 博兴县| 栾城县| 屯昌县| 叶城县| 宁安市| 汝南县| 江川县| 阿克陶县| 大城县| 金湖县| 荔波县| 边坝县| 保定市| 永年县| 大城县| 西丰县| 和林格尔县| 东辽县| 松桃| 吐鲁番市| 哈巴河县| 华坪县| 壤塘县| 曲沃县| 云南省| 讷河市| 思茅市| 鄯善县| 关岭| 古交市|