• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

How do I combining sorting in gridview with checkboxes vb asp.net

On my webpage. www.antagningsstatistik.net/default.aspx  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.

1 Solution
Ramkisan JagtapLead DeveloperCommented:
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

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now