是不是一定要在GridView1_RowDataBound事件中? 
不想在GridView里的属性里设置成一个常量比如10, 
想换成在.cs中定义成一个变量, 哪位高手指点指点呀,? 

解决方案 »

  1.   

    你在后台定义一个int变量aa,然后
    this.GridView1.PageSize = aa;这样不行吗
      

  2.   

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"我在GridView 属性中,想把PageSize 10删除,在.cs中自定义,系统提示属性值无效
      

  3.   

    页面这样布局:每页DropDownList  条
    我想每页显示的页数为下拉框中的值
      

  4.   

    重写gridview控件,自定义属性。
     或 int i = 15;
     this.gvNews.PageSize = i;
      

  5.   

    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                //默认显示第一页,不过在GridView中第一页的页索引是0 
                //注意:在C#中集合里的索引也都是以0开始 
                BindGridView(0); 
            } 
        } 
        //指定绑定页面的数据 
        private void BindGridView(int pageIndex) 
        { 
            //实例化Connection对象 
            SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa"); 
            //实例化Command对象 
            SqlCommand command = new SqlCommand("select * from UserInfo", connection); 
            SqlDataAdapter adapter = new SqlDataAdapter(command); 
            DataTable data = new DataTable(); 
            adapter.Fill(data);         #region 注意这部分代码可以在设计视图中设置,不必写在代码里 
            gvUserList.AllowPaging = true;//设置允许自动分页 
            //gvUserList.AutoGenerateColumns = false;//设置不允许自动绑定列 
            gvUserList.PageSize = 5;//设置每页显示5条记录 
            #endregion 
             
            gvUserList.DataSource = data; 
            gvUserList.PageIndex = pageIndex;//设置当前显示第几页 
            gvUserList.DataBind(); 
        }     //翻页事件 
        protected void gvUserList_PageIndexChanging(object sender, GridViewPageEventArgs e) 
        { 
            //指定新页面,重新绑定数据 
            BindGridView(e.NewPageIndex); 
        }
    //当DropDownList选项变化时重新绑定数据
        private void  DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
    int pageIndex=int.Parse(DropDownList1.SelectedValue);
    BindGridView(pageIndex); 
    }
      

  6.   


    那在asps页面中怎么设定和GridView分页相关的东西?