How do I combining sorting in gridview with checkboxes vb

Posted on 2011-10-09
Last Modified: 2012-05-12
On my webpage.  I have checkboxes to filter the data displayed in the gridview. I works fine with multiple selections. However, I have also enabled sorting on column headers in the gridview using the smart tag in Visual web developer.

When I make a selection with for instance to selections in the checkboxlist and click the button it looks fine. But when I click on a column header to sort the gridview based on the to selections, only data from linked to  one of the two selected values from the checkboxlist will be displayed.

I would apprecitate if some one could give me a hint or maybe even a solution to what is wrong with my code.

I also attach the files here.

Question by:marcgu
    LVL 12

    Accepted Solution

    Please debug your code. I think when you are clicking on row header for sorting it is taking only first selected checkbox as a parameter. try with adding your below code on page load event too.

    Dim csvOfSelectedItems As String = ""
            Dim li As ListItem
            For Each li In CheckBoxList1.Items
                If li.Selected Then
                    csvOfSelectedItems += "'" + li.Text + "',"
                End If

            If csvOfSelectedItems = "" Then
                Response.Write("No item Selected")
                ' Trim the last comma char
                csvOfSelectedItems = csvOfSelectedItems.Substring(0, csvOfSelectedItems.Length - 1)

                ' Prepare Query string
                Dim sqlQuery As String = "SELECT * FROM dbo_statistik WHERE [kommunnamn] IN (" + csvOfSelectedItems + ")"

                ' EXECUTE sqlQuery HERE and use the results.
                SqlDataSource1.SelectCommand = sqlQuery
            End If


    Author Closing Comment

    Thanks a lot! It worked perfectly! Sorry for not checking that first!

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now