国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Repeater全選刪除和分頁實現思路及代碼

2024-07-10 13:17:16
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


<script type="text/javascript">
function SelectAll(box)
{
for(var i=0;i <document.form1.elements.length;i++)
{
var e=document.form1.elements[i];
if((e.type=='checkbox'))
{
var o=e.name.lastIndexOf('cbx');
if(o!=-1)
{
e.checked=box.checked;
}
}
}
}
</script>
<body>
<form runat="server">
<div>
</div>
<asp:Repeater runat="server">
<HeaderTemplate>
<table>
<tr><th><input id= "chkHeader" type= "checkbox" onclick= "SelectAll(this)"/>全選</th><th>報到號</th><th>考生號</th><th>姓名</th><th>身份證號碼</th><th>家庭地址</th><th>類別</th><th>專業</th></tr>
</HeaderTemplate>
<ItemTemplate>
<tr><td ><asp:CheckBox runat="server" /></td><td><asp:Label Text='<%#Eval("id") %>' runat="server" ></asp:Label></td><td><%#Eval("ksh") %></td><td><%#Eval("xm") %></td><td><%#Eval("sfzh") %></td><td><%#Eval("jtdz") %></td><td><%#Eval("jhxzmc") %></td><td><%#Eval("lqzy") %></td></tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<asp:Button runat="server" Text="批量刪除" OnClientClick="return confirm('確定要刪除嗎?該操作不可恢復!!!')" />
<br />
<br />
<webdiyer:AspNetPager runat="server" pagesize="2"
CssClass="anpager" onpagechanged="AspNetPager1_PageChanged"
FirstPageText="首頁" LastPageText="尾頁" NextPageText="下一頁" PrevPageText="上一頁"
ShowMoreButtons="False" ShowPageIndexBox="Never" AlwaysShow="True">
</webdiyer:AspNetPager>
</form>
</body>
==================
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string username = Session["username"].ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["shan"].ConnectionString);
conn.Open();
SqlCommand count = new SqlCommand("select count(*) from do.so where baosongren = '"+username+"'", conn);
benren.RecordCount = (int)count.ExecuteScalar();
conn.Close();
BindData();
}
}
public void BindData()
{
string username = Session["username"].ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["shnn"].ConnectionString);
string sql = "select * from dao where baosongren = '"+username+"' order by ID desc";//這句在大型數據中應該用:select top查詢語句
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, benren.PageSize * (benren.CurrentPageIndex - 1), benren.PageSize, "temptbl");
DataTable dt = ds.Tables["temptbl"];
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
//AspNetPager1.CurrentPageIndex = e.NewPageIndex;
BindData();
}
protected void btnDel_Click(object sender, EventArgs e)
{
string delId = "";
//先遍歷取得選中項
for (int i = 0; i < this.Repeater1.Items.Count; i++)
{
CheckBox cbx = (CheckBox)Repeater1.Items[i].FindControl("cbx");
Label lbl = (Label)Repeater1.Items[i].FindControl("lbl");
if (cbx != null)
{
if (cbx.Checked)
{
delId += lbl.Text + ",";
}
}
}
//去掉最后一個,
delId = (delId + ")").Replace(",)", "");
//Response.Write("刪除的語句是:delete news_sosuo8_ where id_news_ in(" + delId + ")");
//自己寫刪除語句吧
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["shann"].ConnectionString);
SqlCommand del = new SqlCommand("delete so where id in(" + delId + ")", conn);
conn.Open();
int myupdate = del.ExecuteNonQuery();
conn.Close();
if (myupdate > 0)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript'>alert('刪除成功!');</script>");
}
BindData();
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武义县| 禄劝| 宜兰县| 皋兰县| 丹凤县| 长治市| 宜春市| 腾冲县| 兴文县| 平顶山市| 卢龙县| 密山市| 勃利县| 寻甸| 峨山| 胶州市| 武乡县| 章丘市| 台东市| 临洮县| 海兴县| 靖安县| 怀远县| 新余市| 枣强县| 亳州市| 原阳县| 衡山县| 荔浦县| 乐陵市| 霞浦县| 宁海县| 疏勒县| 泸定县| 丰镇市| 宿迁市| 上虞市| 临汾市| 金塔县| 墨竹工卡县| 黔东|