ASP.NET的Web动态控件创建
朋友们帮我用C#语言实现以下的功能!在等待中!!!!!!!!!!!
Dim i As Integer
For i = 0 To IntRowCount - 1
Dim r As TableRow = New TableRow()
Dim c1 As TableCell = New TableCell()
Dim myLabel1 As Label = New Label()
‘这里设置该label的ID,对于不同的label,必须设置成不同的ID,我这里设置成前缀lbl1加字段名的组合,例如lbl1xlmc等。
myLabel1.ID = "Lbl1" & Trim(OleDsField.Tables("Field").Rows(i).Item("column_name")).ToString()
‘下面的条件语句是为了判断数据库中在字段的值是否为空,根据条件赋予label不同的文本。
If OleDsField.Tables("Field").Rows(i).Item("column_title").GetType.ToString = "System.DBNull" Then
myLabel1.Text = ""
Else
myLabel1.Text = Trim(OleDsField.Tables("Field").Rows(i).Item("column_title"))
End If
c1.Controls.Add(myLabel1)
r.Cells.Add(c1)
Dim c2 As TableCell = New TableCell()
Dim mytextbox As TextBox = New TextBox()
mytextbox.ID = "Txt" & Trim(OleDsField.Tables("Field").Rows(i).Item("column_name")).ToString()
If OleDsResult.Tables("Result").Rows(0).Item(i).GetType.ToString = "System.DBNull" Then
mytextbox.Text = ""
Else
mytextbox.Text = Trim(OleDsResult.Tables("Result").Rows(0).Item(i))
End If
If Trim(OleDsField.Tables("Field").Rows(i).Item("column_enable")) = "是" Then
mytextbox.Enabled = True
Else
mytextbox.Enabled = False
End If
c2.Controls.Add(mytextbox)
r.Cells.Add(c2)
Table3.Rows.Add(r)
Next