本文介绍了分页的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public partial class gridviewwithlinq : System.Web.UI.Page
{
    contextDataContext obj = new contextDataContext();
    static int index;

    void Page_Load(object sender, EventArgs e)
    {
        fillgrid(0);
    }

    private void fillgrid(int p)
    {
        var res = (from n in obj.names select n).Skip(index).Take(11);
        gridview1.DataSource = res;
        gridview1.PageIndex = p;
        gridview1.DataBind();
    }
    protected void gridview1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        index += 10;
        gridview1.PageIndex = e.NewPageIndex;
        fillgrid(e.NewPageIndex);
        Response.Write(e.NewPageIndex);
        fillgrid(0);
    }
}




在这里,我有一个问题,就是我无法获取以前的记录..
谁能帮我得到以前的记录




here i have a problem that is i cant get the previous records..
can any one help me to get the previous records

推荐答案

protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }

        protected void BindData()
        {
            string strConnection = \\ur connection string
            SqlConnection con = new SqlConnection(strConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from employee", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            con.Close();
        }
 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }


protected void gridview1_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
if( gridview1.PageIndex>e.NewPageIndex)
       index=index-10;
else
       index += 10;
       gridview1.PageIndex = e.NewPageIndex;
       fillgrid(e.NewPageIndex);
       Response.Write(e.NewPageIndex);
       fillgrid(0);
   }


这篇关于分页的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 16:41