最简单的方法就是使用 StringBuilder类来构建输出表格的内容。举个简单的例子:
using System.Text;//假设已将表中数据查询到 DataTable dt中StringBuilder sb = new StringBuilder();
sb.Append("<Table border=0>");
sb.Append("<tr><td>ID</td><td>Name</td></tr>");for (i=0;i<dt.Rows.Count;i++)
{
  sb.Append("<tr><td>" + dt.Rows[i]["id"].ToString() + "</td><td>" + dt.Rows[i]["name"].ToString() + "</td></tr>");
}
sb.Append("</table>");Response.write(sb.ToString());// 加 CheckBox的功能也很简单。

解决方案 »

  1.   

    为什么不直接将数据绑定到DataGrid或DataList上呢。
      

  2.   

    .aspx
    <asp:Table id="Table1" runat="server" BorderWidth="1px" GridLines="Both"></asp:Table>.aspx.cs
    SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["DSN"]);
    SqlDataAdapter adapter=null;
    DataSet ds=new DataSet();
    try
    {
    conn.Open();
    string sql="select employeeid,firstname,title,city,country,homephone from employees order by employeeid";
    adapter=new SqlDataAdapter(sql,conn);
    adapter.Fill(ds,"employees");
    DataTable dt=ds.Tables["employees"];
    foreach(DataRow dr in dt.Rows)
    {
    TableRow tr=new TableRow();
    TableCell tcell=new TableCell();
    tcell.Controls.Add(new CheckBox());
    tr.Cells.Add(tcell);
    foreach(object cell in dr.ItemArray)
    {
    TableCell tc=new TableCell();
    tc.Text=cell.ToString();
    tr.Cells.Add(tc);
    }
    Table1.Rows.Add(tr);
    tb.Rows.Add(tr);
    }
    }
    catch(Exception exc)
    {
    Response.Write(exc.Message);
    }
    finally
    {
    ds.Dispose();
    adapter.Dispose();
    conn.Close();
    }
      

  3.   

    dim tr as htmltablerow=new htmltablerow
    tr.innerhtml="..."
    你的表名.rows.add(tr)
      

  4.   

    获取被选取的行
    在.aspx中添加
    <asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>在.aspx.cs添加button_click事件
    private void Button1_Click(object sender, System.EventArgs e)
    {
    string Checked="Checked:";
    for(int i=0;i<Table1.Rows.Count;i++)
    {
    if(((CheckBox)Table1.Rows[i].Cells[0].Controls[0]).Checked)
    Checked+=i.ToString()+",";
    }
    Response.Write(Checked);
    }
      

  5.   

    不懂,我刚开始学,没看大家答的,我觉得是不是可以用:
    table.rows.add(row)?