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;
namespace baolong
{
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlTable TABLE1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
{
int pageSize = 5; //每页显示元素个数
int i = 1;
SqlConnection conn = new SqlConnection("data source=localhost;uid=sa;pwd=;initial catalog=northwind");
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select customerid,city,postalcode from customers", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
i++;
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell cell1 = new HtmlTableCell();
cell1.InnerHtml = Convert.ToString(dr[0]);
HtmlTableCell cell2 = new HtmlTableCell();
cell2.InnerHtml = Convert.ToString(dr[1]);
HtmlTableCell cell3 = new HtmlTableCell();
cell3.InnerHtml = Convert.ToString(dr[2]);
tr.Cells.Add(cell1);
tr.Cells.Add(cell2);
tr.Cells.Add(cell3);
if ((i - pageSize) % pageSize == 1)
{
tr.Attributes["class"]="pagebreak";//设置打印标签
}
this.TABLE1.Rows.Add(tr);
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}