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.
Seems like there is no straight forward answer to this. Thanks for the link. 4guysfromrolla is quite popular around developers. But I didn't know they have a tutorial on this. I will read through and hope it helps.
thutaaung
Member
14 Points
29 Posts
Multiple selection on a checkboxlist to filter a datatable vb.net
Feb 27, 2012 10:06 PM|LINK
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
multiselect DataTable checkboxlist
sushanth009
Contributor
6243 Points
1168 Posts
Re: Multiple selection on a checkboxlist to filter a datatable vb.net
Feb 27, 2012 10:54 PM|LINK
You need to iterate thru all the items in the checkbox list and create a filter based on it...
Have a look at this link
http://www.4guysfromrolla.com/articles/012010-1.aspx
thutaaung
Member
14 Points
29 Posts
Re: Multiple selection on a checkboxlist to filter a datatable vb.net
Feb 28, 2012 10:43 AM|LINK
Seems like there is no straight forward answer to this. Thanks for the link. 4guysfromrolla is quite popular around developers. But I didn't know they have a tutorial on this. I will read through and hope it helps.