Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#3.5
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
<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
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 18-Sep-12 0:50am
Edited 18-Sep-12 1:25am
v3
Comments
Tejas_Vaishnav at 18-Sep-12 9:33am
   
for your solutions you need to go for lazy loading concept.
Member 9376025 at 21-Sep-12 5:20am
   
vaishnav.what is the lazy loading concept.you can explain me..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

 protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
         Gridview1.PageSize=Convert.ToInt32(e.NewPageIndex)*10; 
         Gridview1.PageIndex = 0; 
   
        BindGridData();
    }
  Permalink  
Comments
Member 9376025 at 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 at 22-Sep-12 2:04am
   
it means that you have only 10x3=30 records
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,651
1 Sergey Alexandrovich Kryukov 6,400
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,542


Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100