databinding with CheckBoxList

Discussion in 'ASP .Net Web Controls' started by ES, Aug 16, 2005.

  1. ES

    ES Guest

    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
     
    ES, Aug 16, 2005
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders

    Re: Problem with DataBinding and CheckBoxList

    John Saunders, Aug 10, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    522
    Eric Johannsen
    Aug 11, 2003
  2. JD
    Replies:
    5
    Views:
    12,580
    NetArchitect
    Aug 8, 2007
  3. Patrick.O.Ige
    Replies:
    5
    Views:
    19,839
    Patrick.O.Ige
    Jun 19, 2005
  4. Jeppe Jespersen

    2.0 Databinding with CheckboxList

    Jeppe Jespersen, Jan 26, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    578
    Jeppe Jespersen
    Jan 26, 2006
  5. jobs
    Replies:
    0
    Views:
    2,447
  6. Andy B
    Replies:
    0
    Views:
    502
    Andy B
    Apr 21, 2008
  7. Andy B
    Replies:
    0
    Views:
    825
    Andy B
    May 20, 2008
  8. Eran Dvey-Aharon

    Controling the 'selected' property on CheckBoxList while DataBinding()

    Eran Dvey-Aharon, Feb 7, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    345
    IronYuppie
    Feb 18, 2005
Loading...