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
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