Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
Paging in gridview in asp.net using c# in GridView of Asp.net/Ado.net/C#.net(Dotnet)
5627 Views
.aspx page
<asp:GridView ID="listCds" runat="server"
        AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"
        BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="cdNo"
        Width="95%" onrowcancelingedit="listCds_RowCancelingEdit"
        onrowdeleting="listCds_RowDeleting" onrowediting="listCds_RowEditing"
        onrowupdating="listCds_RowUpdating" AllowPaging="True"
        onpageindexchanging="listCds_PageIndexChanging" PageSize="5"  >

Note 
In aspx page in gridview control added these three for paging purpose
AllowPaging="True" onpageindexchanging="listCds_PageIndexChanging" PageSize="5"
page size refers number of rows limit per page
.aspx.cs page Syntax
protected void listCds_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            listCds.PageIndex = e.NewPageIndex;//paging index
            //code to bind the grid view
        }
.aspx.cs page example
protected void listCds_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            listCds.PageIndex = e.NewPageIndex;
            SqlConnection conn = new SqlConnection(@"data source=LAKSHANYA\SQLEXPRESS;database=master;integrated security=true");
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from addcds", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            listCds.DataSource = ds;
            listCds.DataBind();
        }
Preview 
Best Lessons of "Asp.net/Ado.net/C#.net(Dotnet)"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details