Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai from since 2 days iam working with gridview control..i have a database with one table.. that table can have 100 records.. I dont want to retrive all the records at a time.. i wanted to retrive records based on the page size only... for suppose my page size is 10 i wanted to retrieve the records from 0-9 records only from database .. after am clicking on the next page i wanted to retrieve 10-19 records only from database as like that.. can any one help me for this problem..
Thank you
Posted
Updated 26-Jul-12 19:37pm
v2
Comments
U@007 27-Jul-12 1:33am    
don't ask help me edit and remove it

Add Gridview

XML
<asp:gridview id="DgTest" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
           Width="100%" AllowSorting="True" OnRowCommand="DgTest_RowCommand"
           OnRowDataBound="DgTest_RowDataBound" AllowPaging="True"
           onpageindexchanging="DgTest_PageIndexChanging" CaptionAlign="Right">
            <pagersettings firstpagetext="First" lastpagetext="Last">
               Mode="NextPreviousFirstLast" NextPageText="Next"  PreviousPageText="Previous" />
           <columns>
               <asp:boundfield datafield="ID" headertext="Id" />
               <asp:boundfield datafield="NAME" headertext="Name of Emp" />
           </columns>
       </pagersettings></asp:gridview>


Create PageIndexChanging event as

C#
protected void DgTest_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            DgTest.PageIndex = e.NewPageIndex;
            Populate();
        }


C#
private void Populate()
        {
            //Code To get datasource to Databind
        }
 
Share this answer
 
v2
1.please use gridview allow paging property=true
2.gridview pageindex changing event
 
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