Click here to Skip to main content
16,020,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public partial class gridviewwithlinq : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\srikanth\\webprojects\\gridviewwithlinq\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True");
    SqlDataAdapter da;
    int startindex;//it will maintain the page count
    void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["index"] = 0;
            fillgrid();
        }
    }

    private void fillgrid()
    {
        startindex = int.Parse(ViewState["index"].ToString());
        string querry = "SELECT * from(select Row_number() over (order by id) as MyRow,*  from name) as names where MyRow > " + startindex * 10 + " and MyRow < " + ((startindex * 10) + 11) + "";
         DataSet ds = new DataSet();
        da = new SqlDataAdapter(querry, con);
        da.Fill(ds, "p");
        gridview1.DataSource = ds;
        gridview1.DataBind();
        
    }
  
    protected void button2_Click(object sender, EventArgs e)
    {
       
        ViewState["index"] = int.Parse(ViewState["index"].ToString()) + 1;
        Response.Write("the current index is"+" " + ViewState["index"].ToString());
        fillgrid();
        
    }
    protected void button1_Click(object sender, EventArgs e)
    {
       
        ViewState["index"] = int.Parse(ViewState["index"].ToString()) - 1;
        Response.Write("the current index is"+" " + ViewState["index"].ToString());
        fillgrid();
        
    }
    protected void buttonfirst_Click(object sender, EventArgs e)
    {
        ViewState["index"] = startindex;
        Response.Write("the current index is" + " " + startindex);
        fillgrid();
       
    }
    protected void buttonlast_Click(object sender, EventArgs e)
    {
        
    }
}





here i wrote first and next and previous button logics but iam unable to write lastpage button logic.... can any one help me for the last button logic

Posted
Updated 30-Jul-12 19:48pm
v2

 
Share this answer
 
 
Share this answer
 
Comments
_Amy 31-Jul-12 2:24am    
Added nice alternatives. +5!
Hi,
Here you go:
Custom paging in asp.net GridView[^]

I am sure here you'll able to find your logic.


--Amit
 
Share this answer
 
Comments
Vani Kulkarni 31-Jul-12 2:20am    
Good link :)
_Amy 31-Jul-12 2:23am    
Thanks Vani. :)

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