Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In my page load, i called grid() with out searching...If i want search in grid(),it shows no:of records in gridview..Now i click on Pageindex 2 page..then it call page load first...then it call page load method automatically..finally it shows all records ...but we want to display searched record with paging..how can do this..?


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

      }
      catch (Exception ex)
      {         
          
      }
  }
Posted

1 solution

Always Bind GridView inside IsPostBack[^].
C#
private void Page_Load()
{
    if (!IsPostBack)
    {
        grid();
    }
}
 
Share this answer
 
Comments
santhu888 14-Feb-14 3:59am    
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

grid();


}
} I had written already but when i Click on search button It is showing one grid.In that i have more records so that i am addind page index event but it is not working...after showing grid if i click on next page it is showing normal grid before clickng search button
Is it hitting Page Index Changing Event if you put a debugger inside the Event?
santhu888 14-Feb-14 4:41am    
It is hitting..but grid() is calling....by that searched records are not coming only normal grid is showing
Okay, I got the Point now.... As you are calling the grid() again to bind, so it is pulling the all records for the page, but not according to the search text.

So, what you can do is, you have to check whether there is any search Text or not in that grid() method like...

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.
}
}
santhu888 14-Feb-14 5:23am    
This is working...thank you.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900