Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have my grid view and PageIndexChanging event is work fine .But when I make any filtration to my data depending on certain condition and bind the filtred data to my gridview ,for the 1st page it works correctly and then for other pages it loads the same data as previous i.e before filtration.

Can any boy tell me how to handle this type of situation??

C#
protected void gvEmployees_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
      gvEmployees.PageIndex = e.NewPageIndex;
      LoadData();
  }

XML
public void LoadData()
    {
        List<employee> employees = employeeService.GetAllEmployees();
        gvEmployees.DataSource = employees;
        gvEmployees.DataBind();
}

//filtering  employee by salary
protected void btnSearch_Click(object sender, EventArgs e)
    {
string sal= txtSal.Text;
  var employees = employeeService.SearchEmployeeByType(sal);
           
                gvEmployees.DataSource = employees;
                gvEmployees.DataBind();
}</employee>
Posted
Updated 27-Mar-15 2:49am
v3

1 solution

Need to do few small changes your LoadData() method like
C#
public void LoadData()
{
        string sal= txtSal.Text;
        var employees; 
        if(sal.Trim().Equals(string.Empty))
        {
           employees= employeeService.GetAllEmployees();
        }
        else
        {
           employees = employeeService.SearchEmployeeByType(sal);
        }
        gvEmployees.DataSource = employees;
        gvEmployees.DataBind();
}


This should do your job !
Hope, it helps :)
 
Share this answer
 

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