Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:30:38+00:00 2026-05-30T19:30:38+00:00

hope you are doing fine. I have a datatable loaded from a database. I

  • 0

hope you are doing fine.

I have a datatable loaded from a database. I bind the datatable to a gridview on page_load. Now I want to filter the gridview by a user selection so I made a checkboxlist and wrote some code as follow at CheckBoxList1_SelectedIndexChanged

    Dim selectedartist As String = CheckBoxList1.SelectedItem.ToString()
    Dim dTable As DataTable = Session("dTable")
    Dim dTablenew As New DataTable

    Dim str As String = "Song_Artist ='" & selectedartist & "'"
    dTablenew = dTable.Select(str).CopyToDataTable

    GridView1.DataSource = dTablenew
    GridView1.DataBind()

With this code above, it can filter if there is only one selection on the checkboxlist. I try to loop the checkboxlist myself but always ended up in errors. Hope someone can help me out to make this work.

Thanks so much.

L

This is the example of the datatable i have

dataset

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:30:39+00:00Added an answer on May 30, 2026 at 7:30 pm

    Because you have already used a DataTable extension with CopyToDataTable:

    Dim rows = From row In dTable.AsEnumerable()
               From item In CheckBoxList1.Items.Cast(Of ListItem)()
               Where item.Selected = True AndAlso _
               row.Field(Of String)("Song_Artist") = item.Text
               Select row
    If rows.Any() Then
        Dim tblFiltered = tbl.CopyToDataTable()
    End If
    

    LINQ-To-DataSet

    Or in method syntax (in VB.NET not very readable)

    Dim selected = CheckBoxList1.Items.Cast(Of ListItem).
                   Where(Function(i) i.Selected = True).
                   Select(Function(i) i.Text)
    If selected.Any() Then
        Dim rows = dTable.AsEnumerable().
            Where(Function(r) selected.Contains(r.Field(Of String)("Song_Artist")))
        If rows.Any() Then
            Dim tblFiltered = rows.CopyToDataTable()
        End If
    End If
    

    Finally, the NET 2.0 DataTable.Select approach:

    Dim selected As New List(Of String)
    For Each item As ListItem In CheckBoxList1.Items
        If item.Selected Then
            selected.Add(String.Format("'{0}'", item.Text))
        End If
    Next
    If selected.Count <> 0 Then
        Dim rows = dTable.Select(String.Format(
                    "Song_Artist IN ({0})",
                    String.Join(",", selected)))
        If rows.Length <> 0 Then
            Dim tblFiltered = rows.CopyToDataTable()
        End If
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this is something straightforward that I'm doing wrong. I saw something online
Hope I'm asking this correctly: I have a project Projects.Client I have my class
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
Hope to get solution to this problem. I have been stuck on it since
I'm using Fancybox and Zend. Hope the following is clear. On www.example.com/template/edit/id/3 I have
Alright, here's a quick explanation of what I am doing: I have a website
Here's an interesting one... hope I can explain it well... I have a collection
I have a User-Defined Table Type called tvpInsertedColumns : CREATE TYPE [Audit].[tvpInsertedColumns] AS TABLE(
I have a database table that stores imported information. For simplicity, its something like:
this problem has been doing my head in and I hope you can help!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.