程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> 利用DataGrid控件進行分頁實現代碼

利用DataGrid控件進行分頁實現代碼

編輯:關於C#
 

aa.aspx

用DataGrid控件進行分頁

<form id="form1" runat="server">
<div>

<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="true" PageSize="2" OnPageIndexChanged="GridView1_PageIndexChanging"
>
<ItemStyle Font-Size="Small"/>
<HeaderStyle Font-Size="Small" BorderColor="#C0C0FF" BackColor="#99CCCC"/>
<PagerStyle PrevPageText="[上一頁]" NextPageText="[下一頁]" Font-Size="Small" />
</asp:DataGrid><br />

</div>
</form>

aa.aspx.cs

用DataGrid控件進行分頁 - 513394217 - ㄨiao愛

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class aa : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

SqlConnection conn = null;

conn = new SqlConnection();
conn.ConnectionString = "server=PC-4355211\\SQLEXPRESS;Initial Catalog=BookShop;"
+ "User ID=qq;Password=qqpassword";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Books";
cmd.Connection = conn;

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;

DataSet data = new DataSet();
da.Fill(data, "BookShop");

DataGrid1.DataSource = data;
DataGrid1.DataBind();
}


protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.DataGrid1.DataBind();
}

}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved