for(int bmCount = 0; bmCount < DsT_dwdm.Tables["T_DWDM"].Rows.Count; bmCount++)
{
System.Web.UI.WebControls.TableRow Tr_BmInfo = new TableRow();
selfBm = this.Page.Server.HtmlDecode(DsT_dwdm.Tables["T_DWDM"].Rows[bmCount]["BM"].ToString()) + "%";
for(int fxCount = 0; fxCount <= 10; fxCount++)
{
System.Web.UI.WebControls.TableCell Tc_BmInfo = new TableCell();
switch(fxCount)
{
case 0: Tc_BmInfo.Width = 20; Tc_BmInfo.Text = this.Page.Server.HtmlDecode(DsT_dwdm.Tables["T_DWDM"].Rows[bmCount]["BM"].ToString()); break;
case 1: Tc_BmInfo.Width = 130; Tc_BmInfo.Text = this.Page.Server.HtmlDecode(DsT_dwdm.Tables["T_DWDM"].Rows[bmCount]["DWMC"].ToString()); break;
case 2:
Tc_BmInfo.Width = 70;
System.Web.UI.WebControls.TextBox NewTBoxGYME = new TextBox();
NewTBoxGYME.Text = this.SendPolic("GYME",selfBm);
NewTBoxGYME.MaxLength = 4;
NewTBoxGYME.Width = 30;
NewTBoxGYME.CssClass = "textbox";
NewTBoxGYME.ID = "GYME" + this.Page.Server.HtmlDecode(DsT_dwdm.Tables["T_DWDM"].Rows[bmCount]["BM"].ToString());
Tc_BmInfo.Controls.Add(NewTBoxGYME);

System.Web.UI.WebControls.RangeValidator NewRValGYME = new RangeValidator();
NewRValGYME.ControlToValidate = "GYME" + this.Page.Server.HtmlDecode(DsT_dwdm.Tables["T_DWDM"].Rows[bmCount]["BM"].ToString());
NewRValGYME.MaximumValue = "9999";
NewRValGYME.MinimumValue = "0";
NewRValGYME.Type = System.Web.UI.WebControls.ValidationDataType.Integer;
NewRValGYME.ErrorMessage = "有错";
Tc_BmInfo.Controls.Add(NewRValGYME);
break;
}
Tr_BmInfo.Cells.Add(Tc_BmInfo);
}this.TabBm.Rows.Add(Tr_BmInfo);
}

解决方案 »

  1.   

    <%@ Page Language="VB" AutoEventWireup="True" %>
    <html>
    <head>
    <script runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
    Dim row As Integer = 0
    Dim Table1 As HtmlTable = New HtmlTable()Dim numrows As Integer = 10
    Dim numcells As Integer = 6
    Dim j As Integer
    For j = 0 To numrows - 1
    Dim r As New HtmlTableRow()
    If row Mod 2 = 1 Then
    r.BgColor = "Gainsboro"
    End If
    row += 1
    Dim i As Integer
    For i = 0 To numcells - 1
    Dim c As New HtmlTableCell()
    Dim t as TextBox = new TextBox
    t.Text="ok"
    c.Controls.Add(t)
    r.Cells.Add(c)
    Next i
    Table1.Rows.Add(r)
    Next j
    Panel1.Controls.Add(Table1)
    End Sub 
    </script>
    </head>
    <body>  
    <form runat="server">
    <asp:Panel id="Panel1"  runat="server"></asp:Panel>
    </form>
    </body>
    </html>
      

  2.   

    C#: private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    { //create a new HtmlTable object
    HtmlTable table = new HtmlTable();
    HtmlTableRow row;
    HtmlTableCell cell; //set the table's styles
    table.Border = 1;
    table.CellPadding = 0;
    table.CellSpacing = 0;
    table.BorderColor = "red";
    for (int i=0;i<=2;i++)
    {
    //create a new row and set ist background color
    row = new HtmlTableRow();
    row.BgColor = (i%2 == 0 ? "Lightyellow" : "lightcyan"); for (int j=0;j<=1;j++)
    {
    //create a cell and set its text;
    cell = new HtmlTableCell();
    TextBox txtBox = new TextBox();
    cell.Controls.Add(txtBox);
    txtBox.Dispose();

    //add the cell to the current row
    row.Cells.Add(cell);
    }
    table.Rows.Add(row);
    }
    Panel1.Controls.Add(table);
    }
    }<body>  
    <form runat="server">
    <asp:Panel id="Panel1"  runat="server"></asp:Panel>
    </form>
    </body>
      

  3.   

    最简单得 办法 
    就是 放一个lable 
    以下 字符串动态修改 
    LAble.text="<table><tr><td>sds</td></tr></table>"