Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I want to use Gridview with paging and sorting. When I click on the next page it will not show anything and after clicking on the "search" button, it will display the data. I am not using the sqldatasource. I am using it as a 3tier architecture. How to display in single click on the next page button. How to do the page sorting?
I added the code like this
C#
protected void grdViewSearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdViewSearchResult.PageIndex = e.NewPageIndex;
        grdViewSearchResult.DataBind();
    }

Please give me solution for this...
Posted
Updated 25-Oct-10 3:12am
v2

C#
protected void grdViewSearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
      {
            grdViewSearchResult.PageIndex = e.NewPageIndex;
            DataSet ds = new DataSet();
            ds = doctorSearch.getSearchResult();
            grdViewSearchResult.DataSource = ds.Tables[0];
            grdViewSearchResult.DataBind();
      }


If this helped you then please Vote and accept the Answer :rose:
 
Share this answer
 
Comments
Dalek Dave 25-Oct-10 10:46am    
Good Answer.
protected void grdViewSearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
      {
            grdViewSearchResult.PageIndex = e.NewPageIndex;
            grdViewSearchResult.DataSource=//datasource; //BindGrid();
            grdViewSearchResult.DataBind();
      }
 
Share this answer
 
v2
Comments
kevinpj 25-Oct-10 9:23am    
dear madhukk, i tried this, but again i need to click the search button to display the data.
m@dhu 25-Oct-10 9:40am    
You need to bind the gridview which is not in your code.
NMehta83 25-Oct-10 9:57am    
Whatever code you have written in the Search button to display the data that same code you need to write after setting the new page index. MadhuKK is absolutely right.You need to bind the gridview again.
Madhukk, this is my code,
please check this,

<asp:GridView ID="grdViewSearchResult" runat="server"
HorizontalAlign="Center" AllowPaging="True" AllowSorting="True"
onpageindexchanging="grdViewSearchResult_PageIndexChanging"
onsorting="grdViewSearchResult_Sorting" PageSize="5"
EnableSortingAndPagingCallbacks="True">

protected void btnSearch_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds = doctorSearch.getSearchResult();
grdViewSearchResult.DataSource = ds.Tables[0];
grdViewSearchResult.DataBind();
}

protected void grdViewSearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdViewSearchResult.PageIndex = e.NewPageIndex;
grdViewSearchResult.DataSource = ds.Tables[0];
grdViewSearchResult.DataBind();
}
 
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