Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i am taking gridview1 and binding 80 records to that gridview1 and i given paging properties as pagesize=20.it is binding to gridvew successfully. but my problem is when i click on second page again it is binding first 20 records only.i am giving my code below...
XML
<asp:GridView ID="gvInbox" runat="server" Width="100%" AutoGenerateColumns="False" 
        DataKeyNames="MsgID" DataSourceID="sdsInbox" 
        ondatabound="gvInbox_DataBound" 
        onselectedindexchanged="gvInbox_SelectedIndexChanged" 
        onrowcommand="gvInbox_RowCommand" onrowdatabound="gvInbox_RowDataBound" 
        AllowPaging="True" PageSize="20" 
        onpageindexchanging="gvInbox_PageIndexChanging">
        <pagersettings>
          position="Bottom"           
          pagebuttoncount="20"/>
         <pagerstyle backcolor="LightBlue">
          height="30px"
          verticalalign="Bottom"
          horizontalalign="Center"/>

C#
protected void gvInbox_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvInbox.PageIndex = e.NewPageIndex;
    //gvInbox.DataSource = sdsInbox;
    gvInbox.Page.DataBind();
}
Posted
v2
Comments
Osman24 8-May-13 2:27am    
Can you share Page_Load?
ntitish 8-May-13 2:43am    
Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{

if (Session["UserID"] == null)
{
Response.Redirect("Splash.aspx");
}



string sPatientId = "";
GlobalDiagnosticsContext.Set("PatientId", sPatientId);
GlobalDiagnosticsContext.Set("PageViewed", "MsgInbox Page");
GlobalDiagnosticsContext.Set("PageType", "Web");
GlobalDiagnosticsContext.Set("TimeStamp", DateTime.Now.ToString());
logger.Info("***MsgInbox page***");

cMsgTeset obj = new cMsgTeset();
obj.ResetMessages(Session["UserID"].ToString());


// *********UserNotification reset
SQLHelp dataHelper = new SQLHelp();
string cmdIn = "select * from usernotifications where userid='" + Session["UserID"].ToString() + "' and Flag='NR' and Type='Web'";
DataSet ds5 = dataHelper.ExecuteSelectProc(cmdIn);
if (ds5.Tables[0].Rows.Count > 0)
{
string cmdUpNot = "update usernotifications set count=0,Flag='R' where Type='Web' and userid='" + Session["UserID"].ToString() + "'";
int j = dataHelper.Execute_datamodify_Proc(cmdUpNot);
}
//************

}
}
Osman24 8-May-13 3:07am    
I think you have a problem with pagersettings because there is no closing tag, It might be problem but I can not see any wrong part for this problem. Can you share your codes after correction of pagersettings tag
ntitish 8-May-13 3:12am    
sir there was no problem while pasting in code project it is showing like that.....even i corrected that again it is displaying like above..
ntitish 8-May-13 3:26am    
but when i click on last page it displaying last records ....how it possible. why it is not displaying 2,3,4 pages when i click on 2nd page it is displaying 1st page records only same as 3rd and 4th pages also it is displaying same 1st page records

I am not sure about Page.DataBind();
this works for me
C#
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gridView.PageIndex = e.NewPageIndex;
   gridView.DataSource = /* Specify your dataset you want to bind here */
   gridView.DataBind();
}


sources:
Gridview Paging using C#[^]

ASP.NET GridView Paging With Data Bind[^]

GridView Paging[^]
 
Share this answer
 
v2
Comments
ntitish 8-May-13 4:20am    
error is coming sir, error-both data source and data source id are showing remove one thing
The error means that Only one data source you can apply to the gridview. In your case you are binding the gridview using DataSourceID="sdsInbox" as well as in gvInbox_PageIndexChanging. Delete one databinding, it'll work.
Refer the links:
GridView Examples for ASP.NET 2.0: Paging and Sorting the GridView's Data[^]
GridView Paging Sample in ASP.NET[^]

--Amit
 
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