How to check boxes depending on values from database

ddun18

Newcomer
Joined
Dec 2, 2004
Messages
1
In my ASP.net web form, I have a CheckBoxList with 3 checkboxes. I want to be able to have the boxes checked depending on the values retrieved from the database.

<asp:checkboxlist id="CheckBoxListHearFrom" runat="server" RepeatDirection="Horizontal" Width="480px" Height="24px">
<asp:ListItem Value="Manager">Manager</asp:ListItem>
<asp:ListItem Value="CoWorker">CoWorker</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:checkboxlist>

In my Page_load() method, I have a method that looks in the database and returns an array of string containing the possible element values "Manager", "CoWorker", "Other" depending on whether those values exist or not in the database. This method does the correct job.

string[] hearFromArray = displayHearFrom(id);

For example, if the database had "Manager" and "CoWorker" values, then only the "Manager" and "CoWorker" check boxes should be checked. However, I don't know how to make the web form understands which ListItem should have the property Selected="True". How can I do that?
 
Back
Top