日期:2014-05-19  浏览次数:20388 次

我写的DataGrid分页 却分不了页
我把代码拷给大家,大家看看哪里不对?

public   partial   class   newslist   :   System.Web.UI.UserControl
{
        private   string   newTypeID;
        public   string   NewTypeID
        {
                set
                {
                        this.newTypeID   =   value;
                }
        }
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                        if   (!this.IsPostBack)
                        {
                                SqlConnection   con   =   DB.createCon();
                                SqlCommand   cmd   =   new   SqlCommand( "select   newsTypeName   from   newsType   where   newsTypeID= ' "   +   this.newTypeID   +   " ' ",   con);
                                con.Open();
                                string   newTypeName   =   Convert.ToString(cmd.ExecuteScalar());
                                this.Label1.Text   =   newTypeName;
                                cmd.CommandText   =   "select   *   from   newsMaster   where   newsTypeID= ' "   +   this.newTypeID   +   " ' ";
                                this.DataGrid1.DataSource   =   cmd.ExecuteReader();
                                this.DataGrid1.DataBind();
                        }
        }
        protected   void   DataGrid1_PageIndexChanged(object   source,   DataGridPageChangedEventArgs   e)
        {
                this.DataGrid1.CurrentPageIndex   =   e.NewPageIndex;
                this.DataGrid1.DataBind();
        }
}

------解决方案--------------------
看一下你的 PagerStyle 中设置的对吗?
------解决方案--------------------
你allow paging了吗?
------解决方案--------------------
DataGrid-> 右键-> 属性生成器-> 分页-> 允许分页
------解决方案--------------------