日期:2014-05-18  浏览次数:20421 次

高手们帮我看下这个问题有关AspNetPager 和 搜索的关联问题 小弟在线等 急急急。。。
在搜索出来答案后 用AspNetPager分页 到第二页搜做结果就不管用了 源码如下:
public partial class admin_Manage_news : System.Web.UI.Page
{
  string nid = "";
  DataSet ds;
  SqlDataAdapter dr;
  SqlCommand com;
  SqlConnection myConnection = new SqlConnection(
  ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
  protected void Page_Load(object sender, EventArgs e)
  {
  if ((Session["id"] == "") || (Session["id"] == null))
  {
  Response.Write("<script>alert('" + "用户名已超时,请重新登录!!!" + "');top.window.location.href='Default.aspx';</script>");
  }
  if (Request.Params["id"] != null)
  {
  nid = Request.Params["id"];
  }
  if (!Page.IsPostBack)
  {
  myConnection.Open();
  com = new SqlCommand();
  com.Connection = myConnection;
  com.CommandText = "select count(*) from News where News_catid=" + nid + " ";
  AspNetPager1.AlwaysShow = true;
  AspNetPager1.PageSize = 15;
  AspNetPager1.RecordCount = (int)com.ExecuteScalar();

  myConnection.Close();
  bind_news();
  }

  }
  public void bind_news()
  {

  String cmdText = "SELECT News_id,News_title,News_dateandtime from News WHERE News_catid=" + nid + " ORDER BY News_id DESC ";
  dr = new SqlDataAdapter(cmdText, myConnection);
  ds = new DataSet();
  dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "News");
  Show_news.DataSource = ds.Tables["News"];
  Show_news.DataBind();
   
  }
  protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
  {
  AspNetPager1.CurrentPageIndex = e.NewPageIndex;

  bind_news();
  }

  protected void Delet_news(object sender, EventArgs e)
  {
  string kk = "";
  foreach (DataListItem item in Show_news.Items)
  {
  HtmlInputCheckBox chkItem = item.FindControl("chkItem") as HtmlInputCheckBox;
  if (chkItem.Checked)
  {
  kk = kk + chkItem.Value + ",";
  }
  }
  string str = kk.Trim(',');

  string CmdText = "DELETE FROM [News] WHERE News_id in(" + str + ")";
  SqlCommand myCommand = new SqlCommand(CmdText, myConnection);
  int nResult = -1;
  try
  {
  myConnection.Open();
  nResult = myCommand.ExecuteNonQuery();

  }
  catch (SqlException ex)
  {
  throw new Exception(ex.Message, ex);
  }
  finally
  {
  myConnection.Close();
  }
  Response.Write("<script>alert('" + "删除成功" + "');window.location.href='Manage_news.aspx?id="+nid+"';</script>");
  }