Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Page.IsPostBack = False Then
.
.
.
content_count在此被赋值
End If
If viewstate("edit") = False Then
If content_count > 7 Then
question_paper(1, 7)
Else
question_paper(1, content_count)
End If
End If
End Sub
下面是button1过程,问题1,question_paper中的i值没有传递到button1过程中;问题2,按过button1按钮后,panel上的控件被清空了(button1过程中没有清除控件的语句)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim RBLcount As Int16
'检查每一题是否做完
' i = Session("count")
'Response.Write("<script>alert('" & Session("count") & "')</script>")
Response.Write("<script>alert('" & Str(i) & "')</script>")
j = i Mod 7
If j = 0 Then
j = i - 6
Else
j = Int(i / 7) * 7 + 1
End If
Response.Write("<script>alert('" & Str(j) & "')</script>")
For ii = j To i
m = ii Mod 7
If m = 0 Then
m = 7
End If
'Response.Write("<script>alert('" & Str(m) & "')</script>")
'Exit Sub
dyRadioButton = Panel1.FindControl("RadioButtonList" & m)
If dyRadioButton.SelectedIndex = -1 Then
Response.Write("<script>alert('所有题目都必须做!')</script>")
Exit Sub
End If
Next
....
各位大虾,我关于生成动态控件的代码如下,从page-load和button过程中调用
Public Sub question_paper(ByVal n As Int16, ByVal m As Int16)
Panel1.Controls.Clear()
'在panel1上写题目和选项,每页7题
myConn.Open()
For i = n To n + m - 1
m = i Mod 7
If m = 0 Then
m = 7
End If
dylabel = New Label()
dylabel.ID = "Label" & (m + 7)
dylabel.Text = Str(i) + ". " + content(i, 0)
ansno = Trim(content(i, 1))
Panel1.Controls.Add(dylabel)
dylabel.Dispose()
Dim selectstr_ans As String = "select ans_name,ans_mark from ans where ans_no ='" & ansno & "' order by ans_mark desc"
Dim da_ans As New SqlDataAdapter(selectstr_ans, myConn)
Dim ds_ans As New DataSet()
Dim dw_a As DataRow