我做了一个简单的留言板,主要部分的程序如下,采用的是一个用户控件:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection con;
SqlDataAdapter ad;
string sql;
con = new SqlConnection("data source=辜波的机机;initial catalog=DBdingo;user id=sa; password=838282");
sql = "SELECT * FROM [NoteBook] ORDER BY [NoteBook].Ntime ASC";
ad = new SqlDataAdapter(sql,con);
con.Open();
DataSet ds = new DataSet();
try
{
ad.Fill(ds,"notes");
}
finally
{
con.Close();
}
if(ds.Tables["notes"].Rows.Count > 0)
{
Table tb;
TableCell cell;
TableRow tbrow;
Label lbl;
tb = new Table();
foreach(DataRow row in ds.Tables["notes"].Rows)
{
tbrow = new TableRow();
lbl = new Label();
lbl.Text = "留言人:" + row["Noter"].ToString()+"<br>" + "----------------------------------------------------";
lbl.CssClass = "Normal";
cell = new TableCell();
cell.Controls.Add(lbl);
cell.BackColor = System.Drawing.Color.WhiteSmoke;
tbrow.Cells.Add(cell);
tb.Rows.Add(tbrow);
tbrow = new TableRow();
lbl = new Label();
lbl.Text = row["Ncontent"].ToString();
lbl.CssClass = "Normal";
cell = new TableCell();
cell.Controls.Add(lbl);
cell.ForeColor = System.Drawing.Color.Blue;
cell.Width = 600;
tbrow.Cells.Add(cell);
tb.Rows.Add(tbrow);
tbrow = new TableRow();
lbl = new Label();
lbl.Text = "留言时间:" + row["Ntime"].ToString();
lbl.CssClass = "Normal";
cell = new TableCell();
cell.Controls.Add(lbl);
tbrow.Cells.Add(cell);
tb.Rows.Add(tbrow);
tb.BorderWidth = 0;
tb.CellSpacing = 10;
tb.CellPadding = 5;
tb.Width = 700;
}
this.Controls.Add(tb);
}
但是这样就有个问题了,如果有1000条留言那么就会在一个页面上显示,那页面不就成万里长城了啊?请教大家怎么样可以不通过绑定到DataGrid的方式来分页。谢谢大家了.......
[此贴子已经被作者于2005-12-15 20:51:00编辑过]