Multiple Selections in CheckBoxList to Generate a GridView

Last post 05-21-2008 11:31 PM by Qin Dian Tang - MSFT. 1 replies.

Sort Posts:

  • Multiple Selections in CheckBoxList to Generate a GridView

    05-18-2008, 10:41 AM
    • Loading...
    • Gaucho
    • Joined on 04-21-2008, 11:54 AM
    • Corona, California
    • Posts 181

    I found VB code to deal with this, for anyone that wants to avoid some frustration. Obviously you'll have to substitute your own values in the code below for your needs, but you should be able to customize without too much hassle. Here is the code:

    Protected Sub ProductSearch_LocationCheck_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProductSearch_LocationCheck.SelectedIndexChanged
            Dim SupplierSelections As Boolean = False
            Dim SupplierItem As ListItem
            For Each SupplierItem In ProductSearch_LocationCheck.Items
                If SupplierItem.Selected Then
                    SupplierSelections = True
                End If
            Next

            If SupplierSelections = True Then
                Dim SupplierSqlString As String
                SupplierSqlString = "SELECT Products.ProductID, Products.ProductName, CONVERT(char(12),Products.OrderDate,0) AS OrderDate, Products.TimeToDeliver, CONVERT(decimal(6,2),Products.Cost,1) AS Cost, Products.Locality, FROM Products INNER JOIN SKUNumber ON Products.SKUNumberID = SKUNumber.SKUNumberID WHERE "

                For Each SupplierItem In ProductSearch_LocationCheck.Items
                    If SupplierItem.Selected Then
                        SupplierSqlString &= "Products.LocationID = '" & SupplierItem.Value & "' OR "
                    End If
                Next

                SupplierSqlString = Left(SupplierSqlString, Len(SupplierSqlString) - 4)
                SupplierSqlString &= "ORDER By Products.ProductName"
                ProductGrid_SQL.SelectCommand = SupplierSqlString
            End If
        End Sub

    Hope it helps someone... 

  • Re: Multiple Selections in CheckBoxList to Generate a GridView

    05-21-2008, 11:31 PM
    Answer

    Hi Gaucho,

    Thanks so much, Gaucho. This will help others.

    Thanks again!

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter