مشکل در صفحه بندی گرید ویو

masud8002k

عضو جدید
سلام من قبلا از این کد استفاده میکردم برای صفحه بندی اما حالا برای
e.NewPageIndex ایراد میگره ایراد کار کجاست به نظرتون
HTML:
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=db;Integrated Security=True;Pooling=False");
            SqlCommand cmd = new SqlCommand("select * from news order by ID desc ");
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds);

            GridView2.DataSource = ds;
            GridView2.DataBind();

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

        {
            SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=db;Integrated Security=True;Pooling=False");
            SqlCommand cmd = new SqlCommand("select * from news order by ID desc ");
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataSource = ds;
            GridView2.DataBind();

        }
 

heil

عضو جدید
سلام

جقدر کد تکراری نوشتین !!!

این رو به کار ببندین :


کد:
private void GetData()
    {
        SqlCommand SearchCommand = new SqlCommand("select * from news order by ID desc", con);
        
        con.Open();

        DataTable DT = new DataTable();
        SqlDataAdapter DA = new SqlDataAdapter(SearchCommand);
        DA.Fill(DT);

        con.Close();

        ResultGridView.AllowPaging = true;
        ResultGridView.PageSize = 10;

        ResultGridView.DataSource = DT;
        ResultGridView.DataBind();
    }


protected void ResultGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
       ResultGridView.PageIndex=e.NewPageIndex;
       GetData(); 
    }
 

korosh00

عضو جدید
شما باید از سی اس اس استفاده کنید تاجای هر آیتم مثلا تیتر خبر - عکس و غیره را در صفحه مشخص کنید .
در ضمن برای اینکه صفحه قابلیت این را داشته باشه که صفحه به صفحه بشه باید خاصیت

AllowPaging = true;
باشه .
 

Similar threads

بالا