码迷,mamicode.com
首页 > 其他好文 > 详细

GridView 分页

时间:2016-05-16 14:22:47      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

GridView 分页

技术分享

a.gridview控件属性 分页 设置AllowPaging 为True ,pagesize 一页展示的条数

 

前端页面

技术分享
 <%--前端页面--%》
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"></asp:GridView>
View Code

后台代码

技术分享
public partial class Default : System.Web.UI.Page
    {
        SqlConnection connect;
        SqlCommand cmd;
        protected void Page_Load(object sender, EventArgs e)
        {

            GridView1.DataSource = bind();
            GridView1.DataBind();
        }
       /// <summary>
       /// 分页
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataBind();
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <returns></returns>
        public DataSet bind()
        {

            connect = new SqlConnection("server=.;database=SuperMarket;uid=sa;pwd=123");
            cmd = new SqlCommand();
            string sql = "select * from dbo.GoodsTypes";
            cmd.CommandText = sql;
            cmd.Connection = connect;

            connect.Open();

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;



        }
    }
View Code

 

GridView 分页

标签:

原文地址:http://www.cnblogs.com/youchim/p/5497860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!