日期:2014-05-17 浏览次数:20509 次
<%@ Page Language="C#" EnableViewState="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { xx.InputAttributes.Add("onclick", "SelectAll(this)"); System.Data.DataTable dt = new System.Data.DataTable(); if (!Page.IsPostBack) { System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("Id", typeof(System.Int32))); dt.Columns.Add(new System.Data.DataColumn("Name", typeof(System.String))); for (int i = 0; i < 6; i++) { dr = dt.NewRow(); dr[0] = i; dr[1] = "【孟子E章】" + i.ToString(); dt.Rows.Add(dr); } rptList.DataSource = dt; rptList.DataBind(); } } protected void LinkButton1_Click(object sender, EventArgs e) { bool hasChecked = false; for (int i = 0; i < this.rptList.Items.Count; i++) { CheckBox cb = (CheckBox)rptList.Items[i].FindControl("cb_id"); int id = Convert.ToInt32(((Label)rptList.Items[i].FindControl("lb_id")).Text); if (cb.Checked) { Response.Write("<li> delete from T_News where Nid=" + id); hasChecked = true; //DbHelper.NoResultCommand(str); } } if (!hasChecked) { Response.Write("没有选中文本"); } else { //Response.Redirect(Request.UrlReferrer.ToString()); } } </script> <script type="text/javascript"> function SelectAll(chkBox) { s = document.getElementsByTagName("input"); for (i = 0; i < s.length; i++) { if (s[i].type == "checkbox" && s[i].id && s[i].id.indexOf("cb_id") > -1) { s[i].checked = chkBox.checked; } } } </script> <body> <form id="form1" runat="server"> <asp:Repeater ID="rptList" runat="server"> <ItemTemplate> <div> <asp:CheckBox ID="cb_id" runat="server" /><asp:Label ID="lb_id" runat="server" Text='<%#Eval("Id") %>'></asp:Label>