Tony
2006-10-08 01:02:59 UTC
¥H€U¬°§ÚèèŒgªº€@ÓžÕÃD¥ÍŠš¶±,Š³€@Ó°ÝÃD,·íÂIÀ»OK«ö¶sŠZ,©ÒŠ³ªºControl³£·|«·sŠA¥ÍŠš€@Šž,³oŒË·|³yŠš€Ä€Þªºµª®×µLªk¥¿œTŽ£¥æ,œÐÀ°Š£¬Ý€UnŠpŠó§ï.ÁÂÁÂ!Partial Class index1007
Inherits System.Web.UI.Page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'If Not IsPostBack Then
Dim panel1 As Panel = Page.FindControl("Panel1")
Dim DBCon_Title As New Data.OleDb.OleDbConnection
DBCon_Title.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("TestDBconn").ConnectionString
DBCon_Title.Open()
Dim DBTxt_Title As String = "select * from rndtitle"
Dim DBCmd_Title As New Data.OleDb.OleDbCommand
DBCmd_Title.Connection = DBCon_Title
DBCmd_Title.CommandText = DBTxt_Title
Dim Reader_Title As Data.OleDb.OleDbDataReader = DBCmd_Title.ExecuteReader
Dim i_Title As Integer = 1
Do While Reader_Title.Read
Dim Label_Title As New Label
Label_Title.ID = "Label_Title_" & Reader_Title("ID")
Label_Title.Text = i_Title & ". " & Reader_Title("title")
panel1.Controls.Add(Label_Title)
panel1.Controls.Add(New LiteralControl("<br>"))
i_Title = i_Title + 1
Dim DBTxt_Ans As String = "select * from RndAns where TitleID=" & Reader_Title("ID")
Dim DBCmd_Ans As New Data.OleDb.OleDbCommand
DBCmd_Ans.Connection = DBCon_Title
DBCmd_Ans.CommandText = DBTxt_Ans
Dim Reader_Ans As Data.OleDb.OleDbDataReader = DBCmd_Ans.ExecuteReader
Dim i_Ans As Integer = 1
Dim ChkLst_Ans As New CheckBoxList
Do While Reader_Ans.Read
'ChkLst_Ans.ID = Reader_Title("id") & "-" & Reader_Ans("id")
ChkLst_Ans.Items.Add(New ListItem(Reader_Ans("Answer"), Reader_Ans("id")))
Loop
panel1.Controls.Add(ChkLst_Ans)
ChkLst_Ans.ID = Reader_Title("id")
DBCmd_Ans.Dispose()
Loop
DBCmd_Title.Dispose()
DBCon_Title.Close()
Dim OKButton As New Button
OKButton.ID = "Button1"
OKButton.Text = "OK"
'CButton.OnClientClick = "Button1_click"
AddHandler OKButton.Click, AddressOf Button1_Click
panel1.Controls.Add(New LiteralControl("<br>"))
panel1.Controls.Add(OKButton)
'End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If IsPostBack Then
Dim tchklistbox As Control
For Each tchklistbox In Page.FindControl("Panel1").Controls
Select Case True
Case TypeOf tchklistbox Is CheckBoxList
Dim xchklistbox As CheckBoxList = CType(tchklistbox, CheckBoxList)
Response.Write(xchklistbox.ID & "-<br>")
Dim i As Integer
For i = 0 To xchklistbox.Items.Count - 1
If xchklistbox.Items(i).Selected Then
Response.Write(xchklistbox.ID & "ÃDªºµª®×:" & xchklistbox.Items(i).Value & "<br>")
End If
Next
Case TypeOf tchklistbox Is Label
'Response.Write(CType(tchklistbox, Label).Text & "<br>")
End Select
Next
End If
End Sub
End Class
Inherits System.Web.UI.Page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'If Not IsPostBack Then
Dim panel1 As Panel = Page.FindControl("Panel1")
Dim DBCon_Title As New Data.OleDb.OleDbConnection
DBCon_Title.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("TestDBconn").ConnectionString
DBCon_Title.Open()
Dim DBTxt_Title As String = "select * from rndtitle"
Dim DBCmd_Title As New Data.OleDb.OleDbCommand
DBCmd_Title.Connection = DBCon_Title
DBCmd_Title.CommandText = DBTxt_Title
Dim Reader_Title As Data.OleDb.OleDbDataReader = DBCmd_Title.ExecuteReader
Dim i_Title As Integer = 1
Do While Reader_Title.Read
Dim Label_Title As New Label
Label_Title.ID = "Label_Title_" & Reader_Title("ID")
Label_Title.Text = i_Title & ". " & Reader_Title("title")
panel1.Controls.Add(Label_Title)
panel1.Controls.Add(New LiteralControl("<br>"))
i_Title = i_Title + 1
Dim DBTxt_Ans As String = "select * from RndAns where TitleID=" & Reader_Title("ID")
Dim DBCmd_Ans As New Data.OleDb.OleDbCommand
DBCmd_Ans.Connection = DBCon_Title
DBCmd_Ans.CommandText = DBTxt_Ans
Dim Reader_Ans As Data.OleDb.OleDbDataReader = DBCmd_Ans.ExecuteReader
Dim i_Ans As Integer = 1
Dim ChkLst_Ans As New CheckBoxList
Do While Reader_Ans.Read
'ChkLst_Ans.ID = Reader_Title("id") & "-" & Reader_Ans("id")
ChkLst_Ans.Items.Add(New ListItem(Reader_Ans("Answer"), Reader_Ans("id")))
Loop
panel1.Controls.Add(ChkLst_Ans)
ChkLst_Ans.ID = Reader_Title("id")
DBCmd_Ans.Dispose()
Loop
DBCmd_Title.Dispose()
DBCon_Title.Close()
Dim OKButton As New Button
OKButton.ID = "Button1"
OKButton.Text = "OK"
'CButton.OnClientClick = "Button1_click"
AddHandler OKButton.Click, AddressOf Button1_Click
panel1.Controls.Add(New LiteralControl("<br>"))
panel1.Controls.Add(OKButton)
'End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If IsPostBack Then
Dim tchklistbox As Control
For Each tchklistbox In Page.FindControl("Panel1").Controls
Select Case True
Case TypeOf tchklistbox Is CheckBoxList
Dim xchklistbox As CheckBoxList = CType(tchklistbox, CheckBoxList)
Response.Write(xchklistbox.ID & "-<br>")
Dim i As Integer
For i = 0 To xchklistbox.Items.Count - 1
If xchklistbox.Items(i).Selected Then
Response.Write(xchklistbox.ID & "ÃDªºµª®×:" & xchklistbox.Items(i).Value & "<br>")
End If
Next
Case TypeOf tchklistbox Is Label
'Response.Write(CType(tchklistbox, Label).Text & "<br>")
End Select
Next
End If
End Sub
End Class