Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Set value of dynamically created checkboxlist

I have a aspx page vb.net
I am dynamically creating a checkboxlist and adding to the page.

However... I am not able to set the selected value(s)

This is my vb code
Dim dtview As New DataView(dS.Tables(1))
dtview.RowFilter = "PromotionSurveyQuestionID=" & dS.Tables(0).Rows(j)("PromotionSurveyQuestionID").ToString()
If dtview.Count > 3 Then
    ckBoxList.RepeatColumns = 2
Else
    ckBoxList.RepeatColumns = 3
End If
If dtview.Count > 0 Then
    Dim dttemp = New DataTable()
    dttemp = dtview.ToTable()
    For n As Int32 = 0 To dttemp.Rows.Count - 1
        ckBoxList.Items.Add(New ListItem(dttemp.Rows(n)("AnswerText").ToString(), dttemp.Rows(n)("PromotionSurveyAnswerID").ToString()))
        If dttemp.Rows(n)("Selected").ToString() = "1" Then
            ckBoxList.Items.Item(n).Selected = True
       End If
    Next
End If

Open in new window


This is a screen print of my data table (view)
User generated image
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

Thanks