ASP.NET 如何動態增加一個Table


Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim tb As New HtmlTable        Dim tc As New HtmlTableCell        Dim tr As New HtmlTableRow        Dim x1 As Date = Date.Parse("2006/01/01")        Dim x2 As Date = Date.Parse("2006/01/10")        Dim i As Int32 = (x2 - x1).Days        For intLoop As Int32 = 0 To i - 1            tr = New HtmlTableRow       '新增Row
            Dim lbl1 As New Label       '新增一個Label
            lbl1.Text = x1.AddDays(intLoop)
            lbl1.ID = "lbl" & x1.AddDays(intLoop)
            tc.Controls.Add(lbl1)       '將Label加到Column
            tr.Controls.Add(tc)         '將Column 加到 Row
            Dim txt1 As New TextBox
            txt1.ID = "txt" & x1.AddDays(intLoop)
            txt1.AutoPostBack = True
            tc.Controls.Add(txt1)       '將TextBox加到Column
            tr.Controls.Add(tc)         '將Column 加到 Row
        Next
        Form.Controls.Add(tb)           '將Table 加到Form
    End Sub
asy 的小舖Blog
            tc = New HtmlTableCell      '新增Column
            tc = New HtmlTableCell      '新增Column
            tb.Controls.Add(tr)         '將Row 加到Table
該功能會自動新增10個label 及10個textbox


來源

Easy 程式設計心得分享

收藏做為資料參考用

張貼留言

0 留言