Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > databinding with CheckBoxList

Reply
Thread Tools

databinding with CheckBoxList

 
 
ES
Guest
Posts: n/a
 
      08-16-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
databinding checkBoxList to a Dictionary<string, string> object Andy B ASP .Net 0 04-21-2008 06:40 PM
Checkboxlist inside Repeater - doesn't fire click event for Checkboxlist JD ASP .Net 5 08-08-2007 11:28 AM
2.0 Databinding with CheckboxList Jeppe Jespersen ASP .Net 0 01-26-2006 02:43 PM
How to get Selected item in a Databinded CheckBoxList when CheckBoxlist is in a DataList? Patrick.O.Ige ASP .Net 5 06-19-2005 06:11 AM
Re: Problem with DataBinding and CheckBoxList John Saunders ASP .Net 1 08-11-2003 04:15 PM



Advertisments