在asp.net中的搜索按钮中的PageIndexChanging事件?

时间:2014-02-14 09:09:39

标签: asp.net sql-server c#-4.0 page-index-changed

 protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack) 
    {

        grid();


    }
   } 

  protected void btnsearch_Click(object sender, EventArgs e)
{

        objRetailPL.ZoneName = ddlzone.SelectedValue;


        //IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
        //String datetime = txtdate.Text.ToString();
        //DateTime dt = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

        //objRetailPL.date =dt;
        DataTable dtsearch = new DataTable();
        dtsearch = objRetailBAL.searchzone(objRetailPL);
        GVRate.DataSource = dtsearch;
        GVRate.DataBind();



}
   protected void GVRate_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
  try
  {
      GVRate.PageIndex = e.NewPageIndex;
      grid();

  }
  catch (Exception ex)
  {         

  }
 }

我有这个代码用于搜索记录。对于那个网格,我添加了页面索引,但它没有正确显示。当点击搜索按钮时,它显示更多的n个记录,当时页面索引不起作用。它在点击搜索按钮之前调用第一个网格。如何更改我的代码请帮助我.....

1 个答案:

答案 0 :(得分:0)

试试这个......

    private void grid()
   {
      if(!string.IsNullOrEmpty(yourSearchTextBox.Text)
      {
      // Then call search method. Make sure you bind the Grid in that method.
      }
      else
      {
      // Normally Bind the Grid as you are already doing in this method.
      }
   }

你必须检查那个grid()方法中是否有任何搜索文本,如...