In gridview properties, set the pagesize as per your project requirement basis. Add the
GridView ID="GridView1" runat="server" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"
PageSize="5"
gridviewpaging.aspx.cs:
public partial class gridviewpaging : System.Web.UI.Page
{
string conn;
SqlConnection con;
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
conn = "Data Source=LOCALHOST;Initial Catalog=master;Integrated Security=True";
con = new SqlConnection(conn );
con.Open();
da = new SqlDataAdapter("select * from users", con);
ds = new DataSet();
da.Fill(ds);
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
Output:
No comments:
Post a Comment