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) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)