Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

In gridview I have set allowsorting="true".But after running if we click the 2nd page it will not displaying the rows.I have added "Page_indexchanging" code also.Below is the code.Plz help.

protected void grdEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       grdEmployee.PageIndex = e.NewPageIndex;
       grdEmployee.DataBind();
   }



<asp:GridView ID="grdEmployee" runat="server" AutoGenerateEditButton="true" 
        AllowPaging="true" AllowSorting="true" GridLines="Horizontal"  
            AutoGenerateDeleteButton="true" onrowediting="grdEmployee_RowEditing" 
        AutoGenerateColumns="false" DataKeyNames="IncidentNumber"
            onrowupdating="grdEmployee_RowUpdating" ShowFooter="true" 
        CellPadding="3" CellSpacing="3" BorderColor="ActiveBorder"
            onrowcancelingedit="grdEmployee_RowCancelingEdit" AutoGenerateSelectButton="true" 
         onrowdeleting="grdEmployee_RowDeleting" 
            Width="1076px" onpageindexchanging="grdEmployee_PageIndexChanging"
         >
</asp:GridView>
Posted

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    grdEmployee.PageIndex = e.NewPageIndex;
    //rebind your gridview - GetSource(),Datasource of your GirdView
    grdEmployee.DataSource = GetSource();
    grdEmployee.DataBind();

}
 
Share this answer
 
Hey Member 10234093
try to add Data Source again to gridview then call the databind() function
 
Share this answer
 
try like this:-
C#
protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
   
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = dtTray; //your data source
        GridView1.DataBind();
   
}
 
Share this answer
 
Please follow this link GridView Tips and Tricks using ASP.NET 2.0

and see the Page Sorting section.
Happy Coding....!!
 
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