开发者

How can I store and retrieve data from a checkboxlist?

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 sin开发者_JAVA技巧ce 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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜