views:

24

answers:

1

SQL Tables

Listing

ID, Title.....

ListingType

ID, Name

ListingMatrix

ListingID, ListingTypeID

Basically a listing can be more than 1 type and I want that to be able to be shown using the ListingMatrix table. However, I'm having a lot of issues populating the checkboxlist because I have it being sorted by Title to keep it user friendly. I'm using VB.Net, LINQ and MS SQL.

Dim readListingMatrix = (From ListingCategories In db.ListingTypeMatrixes _
                         Where ListingCategories.ListingID = ListingID)

For Each row In readListingMatrix
     CheckBoxListListingCategories.Items(row.ListingTypeID - 1).Selected = True
Next

My issue is storing the checklistbox and editing it. Storing I think I could hack, but editing it is becoming a pain since I can't get the checkboxlist to check the correct boxes since their location changes due to the ORDER BY in my SQL Statement that populates the list.

+1  A: 

Assuming that the value field of your checkboxes is filled with a ListingTypeID, do this:

Dim readListingMatrix = (From ListingCategories In db.ListingTypeMatrixes _
                         Where ListingCategories.ListingID = ListingID)

For Each row In readListingMatrix
    CheckBoxListListingCategories.Items.FindByValue(row.ListingTypeID).Selected = True
Next
Ender
Perfect, I can't believe how quick and easy you made it. Thank you so much!
Landmine
Happy to help :)
Ender