using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; 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.Xml.Linq; public partial class SysAdmin_List : System.Web.UI.Page { static int pageN = 0; static PagedDataSource pds = null;//静态变量只初始化一次 public static string tid; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //if (Request.QueryString["Tid"] != null) //{ // tid = Request.QueryString["Tid"].ToString(); // BindRep(pageN); //} BindRep(pageN); } //BindRep(pageN); } public void BindRep(int pageN) { string str = "select a.id,a.tid,a.title_cn,a.editdate,a.source from newstab as a "; DataTable dt = DBH.DBHelper.GetDataSet(str); pds = new PagedDataSource(); pds.AllowPaging = true; pds.PageSize = 5; pds.DataSource = dt.DefaultView; pds.CurrentPageIndex = pageN;// 获取当前页面, 让下面的 显示当前页面 Repeater1.DataSource = pds; Repeater1.DataBind(); } protected void btnPage_Click(object sender, EventArgs e) { BindRep(0); } protected void btnPageUp_Click(object sender, EventArgs e) { if (pageN > 0) pageN--; BindRep(pageN); } protected void btnPageNext_Click(object sender, EventArgs e) { if (pageN < pds.PageCount - 1) pageN++; BindRep(pageN); } protected void btnPageLast_Click(object sender, EventArgs e) { pageN = pds.PageCount - 1; BindRep(pageN); } protected void chkAll_Click(object sender, EventArgs e) { for (int i = 0; i < this.Repeater1.Items.Count; i++) { CheckBox cbx = (CheckBox)Repeater1.Items[i].FindControl("chkItem"); //Label lbl = (Label)Repeater1.Items[i].FindControl("lbl"); if (cbx != null) { if (cbx.Checked) { cbx.Checked = false; } else { cbx.Checked = true; } } } } protected void ibtdel_Click(object sender, EventArgs e) { string delId = ""; //先遍历取得选中项 for (int i = 0; i < this.Repeater1.Items.Count; i++) { CheckBox cbx = (CheckBox)Repeater1.Items[i].FindControl("chkItem"); Label lbl = (Label)Repeater1.Items[i].FindControl("lblID"); if (cbx != null) { if (cbx.Checked) { delId += lbl.Text + ","; } } } //去掉最后一个, delId = (delId + ")").Replace(",)", ""); if (delId != ")") { string sql = "delete from newstab where id in(" + delId + ")"; int j = DBH.DBHelper.ExecuteNonQuery(sql); if (j > 0) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", ""); BindRep(pageN); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", ""); BindRep(pageN); } } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", ""); BindRep(pageN); } } }