首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

高手们帮小弟我看下这个有关问题有关AspNetPager 和 搜索的关联有关问题 小弟 急

2012-03-06 
高手们帮我看下这个问题有关AspNetPager 和 搜索的关联问题 小弟在线等 急急急。。。在搜索出来答案后 用AspN

高手们帮我看下这个问题有关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>");
  }


  protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  {


  string CKeyWord = "";
  if (KeyWord.Text == "")
  {
  CKeyWord = "";
  }
  else
  {
  CKeyWord = " and News_title like '%" + KeyWord.Text + "%'";
  }
  myConnection.Open();
  com = new SqlCommand();
  com.Connection = myConnection;
  com.CommandText = "select count(*) from News where News_catid=" + nid + "" + CKeyWord + "";
  AspNetPager1.AlwaysShow = true;
  AspNetPager1.PageSize = 15;
  AspNetPager1.RecordCount = (int)com.ExecuteScalar();

  myConnection.Close();
  String cmdText = "SELECT News_id,News_title,News_dateandtime from News WHERE News_catid=" + nid + "" + CKeyWord + "";
  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();  

  }
  
}

前台部分分页代码:
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="15" ShowBoxThreshold="1" AlwaysShow="True" FirstPageText="首页" LastPageText="末页"
NextPageText="下一页" PrevPageText="上一页" onpagechanging="AspNetPager1_PageChanging" UrlPaging="True" CurrentPageButtonClass="cpb" CurrentPageButtonPosition="Center" NumericButtonCount="10" SubmitButtonText="Go" TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" Width="577px" UrlRewritePattern='../pagelist_{0}.aspx?&KeyWord="Request("KeyWord")"' >
  </webdiyer:AspNetPager>

[解决办法]

C# code
  protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)    {        AspNetPager1.CurrentPageIndex = e.NewPageIndex;        bind_news();    }
[解决办法]
还没解决?你的翻页激发的事件不对。打开你的页面设计视图,选中你的分页控件,然后点事件,也就是闪电那图标:双击AspNetPager1_PageChanged事件,在那事件里加 bind_news();
代码为
C# code
 protected void AspNetPager1_PageChanged(object sender, EventArgs e)    {bind_news();} 

热点排行