Hi friends,
I want to know that How can we use paging in the gridview ?
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Prabhu RajaPosted Jan 17, 2012, 1:14 PM
The DataGrid control has built-in support for paging through the records of a data source.
You can get more about Paging with Sample Source from here:
http://msdn.microsoft.com/en-us/library/aa479347.aspx
And Refer this Articles Also: Hope this Will help you.
http://www.c-sharpcorner.com/uploadfile/syedshakeer/paging-for-first-next-previous-and-last-in-gridview/
If this post helps you, then mark as Correct Answer. Thank You
Satyapriya NayakPosted Jan 17, 2012, 11:55 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataTable dataTable;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillVendorGrid();
}
}
private void FillVendorGrid()
{
SqlConnection conn = new SqlConnection(connStr);
dataTable = new DataTable();
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM Vendor";
ad = new SqlDataAdapter(cmd);
ad.Fill(dataTable);
ResultGridView.DataSource = dataTable;
ResultGridView.DataBind();
}
protected void ResultGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
ResultGridView.PageIndex = e.NewPageIndex;
FillVendorGrid();
}
}
Thanks
If this post helps you mark it as answer