2
Reply

how to connect next and previous buttons in gridview using asp.net with c#

prasanna laxmi

prasanna laxmi

16y
13.8k
0
Reply

    Hi, Select Grid View and Select Properties... There see Page Setting Option. FirstPage Text : First Page NextPage Text : Next Page PreviousPage Text : Back Page LastPage Text : Last Page // First page is showing Grid view first records only. //Next page is showing Grid view Next record ( Page size another Property.. This is for How many record Displaying. give me 5 grid view is showing only 5 record at time. //Previous page Displaying before records. //Last page is showing Gird view all last records only

    if ur question is regarding gridview paging then set the allowing paging property as true. u will get next and prev button automatically and wirte the functionality in "pageindexchanging event" or if u want to continue the paging functionality using outside buttons then here is the example given below.

    public partial class _Default : System.Web.UI.Page

    {

    static SqlConnection cn = new SqlConnection("server=DEVAPP;user id=sa;password=sa123;database=test");

    protected void Page_Load(object sender, EventArgs e)

    {

    getdata();

    }

    public void getdata()

    {

    SqlDataAdapter da = new SqlDataAdapter("select * from employee", cn);

    DataSet ds = new DataSet();

    da.Fill(ds, "emp");

    GridView1.DataSource = ds;

    GridView1.DataBind();

    }

    protected void prev_Click(object sender, EventArgs e)

    {

    if (GridView1.PageIndex > 0)

    {

    GridView1.PageIndex = GridView1.PageIndex - 1;

    getdata();

    }

    }

    protected void next_Click(object sender, EventArgs e)

    {

    GridView1.PageIndex = GridView1.PageIndex + 1;

    getdata();

    }

    }