Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Experts,
plz suggest me...i wrote the code for page index changing but i want to display by clicking the page2 the first page records also want to display..means as first pagerecords and second page records..

Here i want to display firstpage record to secondpage records also...
plz help me....

plz help me....the code for that...

my code is..
aspx
XML
<body>
    <form id="form1" runat="server">
    <div>

    <asp:GridView ID="Gridview1" AllowPaging="true"  AutoGenerateColumns="false" PageSize="6" runat="server" DataKeyNames="id" OnPageIndexChanging="gvdetails_PageIndexChanging" Width="300px">
    <Columns>
    <asp:BoundField DataField="id" HeaderText="id"  />
    <asp:BoundField DataField="Name" HeaderText="Name" />
    <asp:BoundField DataField="location" HeaderText="location"/>

    </Columns>

    </asp:GridView>
    </div>
    </form>
</body>

aspx.cs
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridData();
        }      
    }
    private void BindGridData()
    {
        con.Open();
        string s = "select * from contact";
        SqlCommand cmd = new SqlCommand(s, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        Gridview1.DataSource = dt;
        Gridview1.DataBind();
    }

    protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Gridview1.PageIndex = e.NewPageIndex;
        BindGridData();
    }
Posted
Updated 18-Sep-12 1:25am
v3
Comments
Tejas Vaishnav 18-Sep-12 9:33am    
for your solutions you need to go for lazy loading concept.
Member 9376025 21-Sep-12 5:20am    
vaishnav.what is the lazy loading concept.you can explain me..

You just need to change the page size. if you want to view previous data


C#
protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
        Gridview1.PageSize=Convert.ToInt32(e.NewPageIndex)*10;
        Gridview1.PageIndex = 0;

       BindGridData();
   }
 
Share this answer
 
Comments
Member 9376025 21-Sep-12 5:09am    
i used the above code but the secondpage data is displaying upto 10..and on clicking 3rd page all the records is displaying..
arshad alam 22-Sep-12 2:04am    
it means that you have only 10x3=30 records
For this kind of requirement, I guess you have to store the data in ViewState and show it in the second page.

I can give you one link Preserving state of Checkboxes while paging in ASP.Net GridView Control[^], where it preserves the state of Check Boxes in View State.

You can implement the logic as per your requirements.

All the best.
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