databinding with CheckBoxList

E

ES

Hello,
I'm attempting to use a check box list to represent an association between "product" and "departments" in a shopping cart type application. A product can exist in multiple departments. I want the check box list to show which departments the product is currently in, and allow the user to change it. I have a query that returns the DepartmentID, DepartmentName, and a "selected" column that is set to 1 or 0. The selected column indicates if the product is currently associated with the department.

I have successfully bound the control with the department id as the DataValueField, the Department description as the DataTextField, but don't know how tell the control which field in the datasource represents the row's "selected" property.

The data looks like this:
DeptID Dept Selected
1 Department A 1
2 Department B 0
3 Department C 0

My check box list is set up like this:
<asp:CheckBoxList id="chklDepartment" Runat="server" DataTextField="Department" DataValueField="DepartmentID" />

The binding looks like this:
chklDepartment.DataSource = Products.GetProductDepartments(ProductID)
chklDepartment.DataBind()

The goal of course is to display 3 check boxes, the first of which is checked.


Is it possible to tell the control to initially check the rows with a "1" in the selected column in the data?


Thanks
Elton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top