【发布时间】:2011-04-26 16:54:43
【问题描述】:
我正在做一个小项目,但在使用复选框时遇到了一些问题。我通过动态添加行和列的代码向 ASP 表添加了许多复选框。这一切都很好,除非我根据加载预先存在的记录来检查它们。由于某种原因,当将新行添加到表中时,某些复选框被设置为 TRUE。这是代码的小sn-p:
newRow = New TableRow
newRow.ID = "Class_R" + X.ToString.Trim
newRow.Visible = True
newRow.Width = Unit.Percentage(100)
If CD.HasRows Then
While CD.Read() And (Not all_done)
If Y <= 3 Then
newCol = New TableCell
newCol.ID = newRow.ID + "Class_C" + Y.ToString.Trim
newCol.Visible = True
newCol.Width = Unit.Percentage(33)
newChk = New CheckBox
newChk.ID = "chkClass_" + CD("class_id").ToString.Trim
newChk.Text = CD("class_desc").ToString.Trim
newChk.Visible = True
newChk.Checked = False
If Not CD("class_desc").ToString.Trim.ToUpper = "OTHER" Then
newChk.Attributes.Add("onclick", "javascript:chkClass_clicked(this)")
Else
newChk.Attributes.Add("onclick", "javascript:chkClass_Other_clicked(this)")
End If
If Array.IndexOf(arClass, newChk.ID) >= 0 Then
newChk.Checked = True
Else
newChk.Checked = False
End If
newCol.Controls.Add(newChk)
If CD("class_desc").ToString.Trim.ToUpper = "OTHER" Then
newTxt = New TextBox
newTxt.ID = "txtClass_" + CD("class_id").ToString.Trim
newTxt.Attributes.Add("onblur", "javascript:update_class_txt_value(this)")
newChk.Checked = IIf(hidClass_chk.Value = "True", True, False)
If newChk.Checked = False Then
newTxt.Attributes.Add("style", "display:none")
Else
newTxt.Attributes.Add("style", "display:inline")
End If
newTxt.Text = hidClass_txt.Value
newCol.Controls.Add(newTxt)
End If
newRow.Cells.Add(newCol)
Y += 1
Else
tblClass.Rows.Add(newRow)
X += 1
newRow = New TableRow
newRow.ID = "Class_R" + X.ToString.Trim
newRow.Visible = True
newRow.Width = Unit.Percentage(100)
Y = 1
newCol = New TableCell
newCol.ID = newRow.ID + "Class_C" + Y.ToString.Trim
newCol.Visible = True
newCol.Width = Unit.Percentage(33)
newChk = New CheckBox
newChk.ID = "chkClass_" + CD("class_id").ToString.Trim
newChk.Text = CD("class_desc").ToString.Trim
newChk.Visible = True
newChk.Checked = False
If Not CD("class_desc").ToString.Trim.ToUpper = "OTHER" Then
newChk.Attributes.Add("onclick", "javascript:chkClass_clicked(this)")
Else
newChk.Attributes.Add("onclick", "javascript:chkClass_Other_clicked(this)")
End If
If Array.IndexOf(arClass, newChk.ID) >= 0 Then
newChk.Checked = True
Else
newChk.Checked = False
End If
newCol.Controls.Add(newChk)
If CD("class_desc").ToString.Trim.ToUpper = "OTHER" Then
newTxt = New TextBox
newTxt.ID = "txtClass_" + CD("class_id").ToString.Trim
newTxt.Attributes.Add("onblur", "javascript:update_class_txt_value(this)")
newChk.Checked = IIf(hidClass_chk.Value = "True", True, False)
If newChk.Checked = False Then
newTxt.Attributes.Add("style", "display:none")
Else
newTxt.Attributes.Add("style", "display:inline")
End If
newTxt.Text = hidClass_txt.Value
newCol.Controls.Add(newTxt)
End If
newRow.Cells.Add(newCol)
Y += 1
End If
*'This is the line causing the checked state to change'*
tblClass.Rows.Add(newRow)
End While
任何见解都会很棒。
谢谢,
【问题讨论】:
标签: javascript asp.net html vb.net