CheckBoxList can not be Pre-loaded
I have coded a Sub btnSubmit_Click to insert the selected checkboxes of a ChecBoxList to the database table. Then in Sub Page_Load, I coded the following loop to set currentCheckBox selected = true whenever the currentCheckBox is not Nothing by Find the checkboxes By reading the "TestName" from the database.
After more a week's testing, I found out that the currentCheckBox was 'not Nothing' only when the TestNames were added manually to the database table. The TestNames inserted into the database table by the btnSubmit_click were Nothing and not selected as Checked.
I think the currentCheckBox, Nothing or not, was not activated by the btnSubmit_Click. More interesting, the database did show the TestNames added by btnSubmit_Click, but their currentCheckBoxes were not 'not Nothing' while the TestNames added manually were 'not Nothing'. Why? Something wrong with the FindByText code? I tried FindByValue -- same result. Any suggestions?
************************************************** ****
Do While objReader.Read()
Dim currentCheckBox As ListItem = cblTests.Items.FindByValue(objReader("TestName").T oString())
If currentCheckBox IsNot Nothing Then
currentCheckBox.Selected = True
End If
Loop
__________________
C. Jeffrey Wang
|