public void BindData() { string title = txtTitle.Text.Trim(); int status = Convert.ToInt32(dropStatus.SelectedValue); int type = 0; if (dropNewsType.SelectedItem.Text != "显示全部") { type = Convert.ToInt32(dropNewsType.SelectedValue); } DataTable dt = NewsBll.getNews(title, status, type); if (dt.Rows.Count > 0) { AspNetPager1.RecordCount = dt.Rows.Count; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dt.DefaultView; pds.PageSize = AspNetPager1.PageSize; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; dgNews.DataSource = pds; dgNews.DataBind(); } else { dgNews.DataSource = null; dgNews.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindDrop(); if (Request.QueryString["id"] != null && Request.QueryString["id"] != "") { string title = ""; int status = 2; int type = Convert.ToInt32(Request.QueryString["id"]); dropNewsType.SelectedValue = type.ToString(); DataTable dt = NewsBll.getNews(title, status, type); if (dt.Rows.Count > 0) { AspNetPager1.RecordCount = dt.Rows.Count; PagedDataSource pds = new PagedDataSource(); pds.DataSource = dt.DefaultView; pds.PageSize = AspNetPager1.PageSize; pds.AllowPaging = true; pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; dgNews.DataSource = pds; dgNews.DataBind(); } else { dgNews.DataSource = null; dgNews.DataBind(); } } else { BindData(); } } }