asp.net repeater實(shí)現(xiàn)批量刪除
更新時(shí)間:2009年03月26日 01:52:38 作者:
asp.net repeater實(shí)現(xiàn)批量刪除實(shí)現(xiàn)效果代碼
詳細(xì)的代碼:
aspx頁(yè)面的body區(qū)域:
復(fù)制代碼 代碼如下:
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Repeater ID="rptNews" runat="server" onprerender="rptNews_PreRender">
<HeaderTemplate>
<table border="1">
<tr>
<th>選擇</th>
<th>id</th>
<th>標(biāo)題</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="cbx" runat="server" /></td>
<td><asp:Label id="lbl" Text='<%#Eval("id_news_") %>' runat="server" ></asp:Label></td>
<td><%#Eval("title_news_") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Button ID="btnDel" runat="server" onclick="btnDel_Click" Text="批量刪除" OnClientClick="return delIt()" />
</form>
</body>
head區(qū)域主要是一段按下“批量刪除”之后要處理的事件,就是上面的

代碼如下:
復(fù)制代碼 代碼如下:
function delIt()
{
var cbxBool = 0;
for(var i = 0;i < cbxArray.length;i++){
var obj = document.getElementById(cbxArray[i]);
if(obj.checked == true){
cbxBool = 1;
break;
}
}
if(cbxBool == 1){
var result = confirm("操作不可以恢復(fù),確定當(dāng)前操作嗎?");
if(result){
return true;
}
}else{
alert("您還沒(méi)有選中項(xiàng)");
return false;
}
return false;
}
cs的全部代碼:
復(fù)制代碼 代碼如下:
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bind();
}
}
//綁定數(shù)據(jù)
private void bind()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ToString());
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select top 10 id_news_,title_news_ from news_sosuo8_", conn);
da.Fill(ds);
this.rptNews.DataSource = ds; //綁定dataset
this.rptNews.DataBind();//開始綁定
conn.Close();
}
protected void btnDel_Click(object sender, EventArgs e)
{
string delId = "";
//先遍歷取得選中項(xiàng)
for (int i = 0; i < this.rptNews.Items.Count; i++)
{
CheckBox cbx = (CheckBox)rptNews.Items[i].FindControl("cbx");
Label lbl = (Label)rptNews.Items[i].FindControl("lbl");
if (cbx != null)
{
if (cbx.Checked)
{
delId += lbl.Text + ",";
}
}
}
//去掉最后一個(gè),
delId = (delId + ")").Replace(",)", "");
Response.Write("刪除的語(yǔ)句是:delete news_sosuo8_ where id_news_ in(" + delId + ")");
//自己寫刪除語(yǔ)句吧
bind();
}
protected void rptNews_PreRender(object sender, EventArgs e)
{
prerepater(rptNews, this);
}
//這個(gè)是通用方法用于在公用類庫(kù)中調(diào)用
public static void prerepater(Repeater repeater, System.Web.UI.Page page)
{
ClientScriptManager cs = page.ClientScript;
for (int i = 0; i < repeater.Items.Count; i++)
{
CheckBox cbx = (CheckBox)repeater.Items[i].FindControl("cbx");
//將相應(yīng)的服務(wù)器控件的ClientId注冊(cè)到客戶端JavaScript數(shù)組
cs.RegisterArrayDeclaration("cbxArray", String.Concat("'", cbx.ClientID, "'"));
}
}
}
您可能感興趣的文章:
- ASP.NET repeater添加序號(hào)列的方法
- asp.net Repeater取得CheckBox選中的某行某個(gè)值的c#寫法
- asp.net repeater手寫分頁(yè)實(shí)例代碼
- asp.net Repeater之非常好的數(shù)據(jù)分頁(yè)
- asp.net中讓Repeater和GridView支持DataPager分頁(yè)
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)
- asp.net 遍歷repeater中的控件的幾種方式
- asp.net下Repeater使用 AspNetPager分頁(yè)控件
- asp.net Repeater控件的說(shuō)明及詳細(xì)介紹及使用方法
- asp.net Repeater 數(shù)據(jù)綁定代碼
- JQuery實(shí)現(xiàn)Repeater無(wú)刷新批量刪除(附后臺(tái)asp.net源碼)
- 決定何時(shí)使用 DataGrid、DataList 或 Repeater(ASP.NET 技術(shù)文章)
- ASP.NET筆記之 Repeater的使用
- asp.net DataList與Repeater用法區(qū)別
- 詳解ASP.NET數(shù)據(jù)綁定操作中Repeater控件的用法
相關(guān)文章
Entity Framework Core延遲加載(懶加載)用法
這篇文章介紹了Entity Framework Core延遲加載(懶加載)的使用方式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02為自己的ASP網(wǎng)站系統(tǒng)構(gòu)建一套標(biāo)記語(yǔ)言
為自己的ASP網(wǎng)站系統(tǒng)構(gòu)建一套標(biāo)記語(yǔ)言...2006-09-09asp.net中url地址傳送中文參數(shù)時(shí)的兩種解決方案
前天遇到一個(gè)地址傳遞中文參數(shù)變?yōu)閬y碼的問(wèn)題,同樣的兩個(gè)web Project,一個(gè)是vs2003,一個(gè)是vs2005,前者可以,后者就是不可以。2009-11-11ASP.NET 獲取存儲(chǔ)過(guò)程返回值的實(shí)現(xiàn)代碼
ASP.NET 獲取存儲(chǔ)過(guò)程返回值的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-12-12詳解mvc使用JsonResult返回Json數(shù)據(jù)
這篇文章主要介紹了詳解mvc使用JsonResult返回Json數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-01-01ubuntu16.4下用jexus部署ASP.NET Core環(huán)境
這篇文章主要以圖文結(jié)合的方式介紹了ubuntu16.4下ASP.NET Core部署環(huán)境搭建步驟,感興趣的小伙伴們可以參考一下2016-07-07自動(dòng)類型安全的REST.NET標(biāo)準(zhǔn)庫(kù)refit
這篇文章介紹了自動(dòng)類型安全的REST.NET標(biāo)準(zhǔn)庫(kù)refit,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04