我的代码如下: Dim ww1 As New ArrayList Dim ww2 As New ArrayList Dim ww3 As New ArrayList Dim myDs As New DataSet Dim aa As New TextBox Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ww1.Clear() ww2.Clear() drawTable() End SubPrivate Sub drawTable() conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../") & "db\xck.mdb;" Dim cn As New OleDb.OleDbConnection(conStr) Dim sql As String = "select 单位 from units" Dim da As New OleDb.OleDbDataAdapter(sql, cn) Dim dr As OleDb.OleDbDataReader cn.Open() da.Fill(myDs) cn.Close() 'myDs.Tables(0).Columns.Add("胜利日报") 'myDs.Tables(0).Columns.Add("电视新闻") 'myDs.Tables(0).Columns.Add("石化报") Dim myRow As New TableRow myRow.Height = New Web.UI.WebControls.Unit("30") Dim myCell1 As New TableCell myCell1.BorderColor = Color.FromArgb(66, 255, 204) myCell1.BorderWidth = New Web.UI.WebControls.Unit("1") myCell1.Text = "单位" myRow.Cells.Add(myCell1) Dim myCell2 As New TableCell myCell2.BorderColor = Color.FromArgb(66, 255, 204) myCell2.BorderWidth = New Web.UI.WebControls.Unit("1") myCell2.Text = "胜利日报" myRow.Cells.Add(myCell2) Dim myCell3 As New TableCell myCell3.BorderColor = Color.FromArgb(66, 255, 204) myCell3.BorderWidth = New Web.UI.WebControls.Unit("1") myCell3.Text = "电视新闻" myRow.Cells.Add(myCell3) Dim myCell4 As New TableCell myCell4.BorderColor = Color.FromArgb(66, 255, 204) myCell4.BorderWidth = New Web.UI.WebControls.Unit("1") myCell4.Text = "石化报" myRow.Cells.Add(myCell4) Table1.Controls.Add(myRow) For i As Int16 = 0 To Me.myDs.Tables(0).Rows.Count - 1 Dim row As New TableRow row.Height = New Web.UI.WebControls.Unit("20") Dim cell0 As New TableCell cell0.BorderColor = Color.FromArgb(66, 255, 204) cell0.BorderWidth = New Web.UI.WebControls.Unit("1") cell0.Text = Me.myDs.Tables(0).Rows(i).Item(0) row.Controls.Add(cell0) Dim cell1 As New TableCell cell1.BorderColor = Color.FromArgb(66, 255, 204) cell1.BorderWidth = New Web.UI.WebControls.Unit("1") Dim txt1 As New TextBox cell1.Controls.Add(txt1) row.Controls.Add(cell1) Dim cell2 As New TableCell cell2.BorderColor = Color.FromArgb(66, 255, 204) cell2.BorderWidth = New Web.UI.WebControls.Unit("1") Dim txt2 As New TextBox cell2.Controls.Add(txt2) row.Controls.Add(cell2) Dim cell3 As New TableCell cell3.BorderColor = Color.FromArgb(66, 255, 204) cell3.BorderWidth = New Web.UI.WebControls.Unit("1") Dim txt3 As New TextBox cell3.Controls.Add(txt3) row.Controls.Add(cell3) Table1.Controls.Add(row) Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For i As Int16 = 0 To ww1.Count - 1 If CType(ww1(i), TextBox).Text.Trim = "" Then CType(ww1(i), TextBox).Text = 0 End If If CType(ww2(i), TextBox).Text.Trim = "" Then CType(ww2(i), TextBox).Text = 0 End If If CType(ww3(i), TextBox).Text.Trim = "" Then CType(ww3(i), TextBox).Text = 0 End If Next end sub 点击button1后并没有任何反应
For i As Int16 = 0 To ww1.Count - 1 /////// 没看到你使用ww1
次时加的控件,可以访问其属性
protected System.Web.UI.WebControls.Button Button1;
private TextBox t=new TextBox();
private void Page_Load(object sender, System.EventArgs e)
{
this.Controls[1].Controls.Add(t);
}
private void Button1_Click(object sender, System.EventArgs e)
{
t.Text ="good";
}
Dim ww1 As New ArrayList
Dim ww2 As New ArrayList
Dim ww3 As New ArrayList
Dim myDs As New DataSet Dim aa As New TextBox Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ww1.Clear()
ww2.Clear()
drawTable()
End SubPrivate Sub drawTable()
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../") & "db\xck.mdb;"
Dim cn As New OleDb.OleDbConnection(conStr)
Dim sql As String = "select 单位 from units"
Dim da As New OleDb.OleDbDataAdapter(sql, cn)
Dim dr As OleDb.OleDbDataReader
cn.Open()
da.Fill(myDs)
cn.Close()
'myDs.Tables(0).Columns.Add("胜利日报")
'myDs.Tables(0).Columns.Add("电视新闻")
'myDs.Tables(0).Columns.Add("石化报") Dim myRow As New TableRow
myRow.Height = New Web.UI.WebControls.Unit("30")
Dim myCell1 As New TableCell
myCell1.BorderColor = Color.FromArgb(66, 255, 204)
myCell1.BorderWidth = New Web.UI.WebControls.Unit("1")
myCell1.Text = "单位"
myRow.Cells.Add(myCell1) Dim myCell2 As New TableCell
myCell2.BorderColor = Color.FromArgb(66, 255, 204)
myCell2.BorderWidth = New Web.UI.WebControls.Unit("1")
myCell2.Text = "胜利日报"
myRow.Cells.Add(myCell2) Dim myCell3 As New TableCell
myCell3.BorderColor = Color.FromArgb(66, 255, 204)
myCell3.BorderWidth = New Web.UI.WebControls.Unit("1")
myCell3.Text = "电视新闻"
myRow.Cells.Add(myCell3) Dim myCell4 As New TableCell
myCell4.BorderColor = Color.FromArgb(66, 255, 204)
myCell4.BorderWidth = New Web.UI.WebControls.Unit("1")
myCell4.Text = "石化报"
myRow.Cells.Add(myCell4) Table1.Controls.Add(myRow) For i As Int16 = 0 To Me.myDs.Tables(0).Rows.Count - 1 Dim row As New TableRow
row.Height = New Web.UI.WebControls.Unit("20") Dim cell0 As New TableCell
cell0.BorderColor = Color.FromArgb(66, 255, 204)
cell0.BorderWidth = New Web.UI.WebControls.Unit("1")
cell0.Text = Me.myDs.Tables(0).Rows(i).Item(0)
row.Controls.Add(cell0)
Dim cell1 As New TableCell
cell1.BorderColor = Color.FromArgb(66, 255, 204)
cell1.BorderWidth = New Web.UI.WebControls.Unit("1")
Dim txt1 As New TextBox
cell1.Controls.Add(txt1)
row.Controls.Add(cell1) Dim cell2 As New TableCell
cell2.BorderColor = Color.FromArgb(66, 255, 204)
cell2.BorderWidth = New Web.UI.WebControls.Unit("1")
Dim txt2 As New TextBox
cell2.Controls.Add(txt2)
row.Controls.Add(cell2) Dim cell3 As New TableCell
cell3.BorderColor = Color.FromArgb(66, 255, 204)
cell3.BorderWidth = New Web.UI.WebControls.Unit("1")
Dim txt3 As New TextBox
cell3.Controls.Add(txt3)
row.Controls.Add(cell3) Table1.Controls.Add(row)
Next
End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Int16 = 0 To ww1.Count - 1
If CType(ww1(i), TextBox).Text.Trim = "" Then
CType(ww1(i), TextBox).Text = 0
End If
If CType(ww2(i), TextBox).Text.Trim = "" Then
CType(ww2(i), TextBox).Text = 0
End If
If CType(ww3(i), TextBox).Text.Trim = "" Then
CType(ww3(i), TextBox).Text = 0
End If
Next
end sub
点击button1后并没有任何反应
///////
没看到你使用ww1