标签:
GridView 分页
a.gridview控件属性 分页 设置AllowPaging 为True ,pagesize 一页展示的条数
前端页面
<%--前端页面--%》 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"></asp:GridView>
后台代码
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; } }
标签:
原文地址:http://www.cnblogs.com/youchim/p/5497860.html