Click here to Skip to main content
15,915,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I click page number 2 it returns same page.
And I click again it returns next page but previuos page data.
My gridview is....
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" 
            ToolTip="Double click for Detail" 
            onpageindexchanging="GridView1_PageIndexChanging"  align="center"
            onrowdatabound="GridView1_RowDataBound" 
          PageSize="10" 
            ShowFooter="True" Caption="Full Detail" onselectedindexchanged="GridView1_SelectedIndexChanged" 
         >
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" Font-Size="Small" />
            <Columns>
                <asp:BoundField DataField="punchdate" HeaderText="PUNCH DATE" />
                <asp:BoundField DataField="timein" HeaderText="IN TIME">
                <ItemStyle HorizontalAlign="Left" />
                 </asp:BoundField>
                <asp:BoundField DataField="timeout" HeaderText="OUT TIME">
                 </asp:BoundField>
            </Columns> 
           <FooterStyle BackColor="#5D7B9D"  ForeColor="White" />
                   <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <selectedrowstyle backcolor="#E2DED6" forecolor="#333333" />
                   <HeaderStyle BackColor="#5D7B9D"  ForeColor="White" Font-Size="Medium" />
                  <EditRowStyle BackColor="#999999" />
                   <AlternatingRowStyle BackColor="PaleGoldenrod" />
        </asp:GridView>
and pageindexedchange event code
C#
protected void GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)
       {
          GridView1.PageIndex = e.NewPageIndex;
           GridView1.SelectedIndex = -1;
                 }

What should I do?
Posted
Updated 26-Jun-12 22:28pm
v2

Looks like you forgot to rebind the gridview. All you need to do is increase the page count and rebind the grid. .NET will automatically show the correct rows.

Here, have a look at these sample article:
MSDN: GridView Examples for ASP.NET 2.0: Paging and Sorting the GridView's Data[^]
GridView Paging Sample in ASP.NET[^]
 
Share this answer
 
Comments
comeshyamala 27-Jun-12 5:12am    
while binding the gridview,
i shouldn't use select * from table.
Because im generating different set of datas according to my conditions.
How to bind the grid without using select *....?
Help me pls.
Sandeep Mewara 28-Jun-12 7:40am    
Hmm, it looks like you got multiple accounts:
http://www.codeproject.com/script/Membership/View.aspx?mid=9084528
http://www.codeproject.com/script/Membership/View.aspx?mid=7909353
http://www.codeproject.com/script/Membership/View.aspx?mid=9043577

Why so?
Bind your gridview again...


C#
GridView1.PageIndex = e.NewPageIndex;
GridView1.SelectedIndex = -1;
bindgrid();



Thanks
 
Share this answer
 
Comments
comeshyamala 27-Jun-12 5:10am    
Im also facing the same problem. I need to generate different set of table datas as per my condition. In such case, i cannot give select * from table in bindgrid().
how to solve this issue?
AshishChaudha 27-Jun-12 5:16am    
how you had bind your gridview?..didn't made a function in all your condition exists??
Member 7909353 27-Jun-12 5:28am    
I bind data by below code
SqlCommand cmd = new SqlCommand("AttendenceViewSP", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Option", SqlDbType.Int, 3).Value = 0;
cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value = UserNameTextBox.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = PasswordTextBox.Text;
cmd.Parameters.Add("@year", SqlDbType.VarChar, 100).Value = yearDropDownList.SelectedItem.Text;
cmd.Parameters.Add("@month", SqlDbType.VarChar, 100).Value = monthDDL.SelectedItem.Text;

SqlParameter p1 = new SqlParameter("ret", SqlDbType.Int);
p1.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(p1);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.Fill(ds);
string dds = ds.Tables[0].Rows[0][1].ToString();


GridView1.DataSource = ds;
GridView1.DataBind();

ad.Dispose();
cmd.Dispose();
in button event
as you suggest,gridview is disable.
AshishChaudha 27-Jun-12 5:37am    
Put all your code in a function than call that function as you required..
Member 7909353 27-Jun-12 5:50am    
When gridview has all data, why we required to make function it is again server hitting.
create session
C#
Session["grid"] = ds;
protected void GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)
        {
           GridView1.PageIndex = e.NewPageIndex;        
            GridView1.SelectedIndex = -1;
GridView1.DataSource=Session["grid"] ;
GridView1.DataBind();
                  }
 
Share this answer
 
Comments
Rahul Rajat Singh 27-Jun-12 6:50am    
good suggestion. this should work.

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