Last post Jun 25, 2007 10:36 AM by scampione
Jun 13, 2007 09:59 PM|darkknight187|LINK
I am using a gridview to display data from my database. And I would like to filter the search results by using a checkbox list.
The problem is that the checkbox list has three selections, box1, box2, box3. And when a search is performed it will pull back only one of the selections.
It does work for any of the three, but if more than one is selected, it will pull back the first box it comes to and display the results.
The AdTypeList is an integer, in the same basic format that the classifieds kit came in.
I can't seem to get this right, and of course I'm sure it's something simple.
Thank you in advance
Jun 13, 2007 11:48 PM|Prashant Kumar|LINK
In your codebehind, there must be code to check the selected checkbox and get the data accordingly.
You have to modify that portion of the code to check for all the selected checkboxes.
Jun 14, 2007 09:52 PM|darkknight187|LINK
I have tried many variations, but no luck.
Can you give me an example of VB code for it?
Jun 16, 2007 09:49 PM|darkknight187|LINK
Does anyone have any ideas how to do this?
Jun 17, 2007 02:15 AM|Prashant Kumar|LINK
Please post your code and I'll help you fix it.
Jun 17, 2007 11:12 AM|darkknight187|LINK
The thing is all I can seem to do is get a code to work to count which box is selected, and if i use a lable it will display the correct boxes.
s = s & AdTypeList.Items(i).Text
s = s &
Label1.Text = s
But I cannot get it into the search results. ("AdTypeList" is the checkboxlist control)
I'm still looking for an better way of doing this, but I'm thinking maybe I should just make CheckBoxList for each of the values.
At least then I know it would work, I just thought I would be using more info than needed, and I was trying to make the searches faster.
Jun 18, 2007 10:57 AM|Prashant Kumar|LINK
I had a look at the Classifieds starter kit. The database has a stored procedure "GetAllAdsByQuery" which is used by the select methods of the object datasource.
This procedure expects only a single AdType at a time or a null in which case it will return all the adTypes. In case you want to search for more than one adType in one select (like you are trying to do), you will have to customize the code to support it
across all the different layers and the database.
Check the following forum, maybe someone has already customized it to support this functionality.
I hope I didn't miss something.
Whatever I said above is based on the fact that you are trying to use sqldatasource.
In case you decide to do it in codebehind, you can achieve your goal without any customization to the various layers or the database.
The select methods return datatables that can be filtered in the codebehind before binding to the gridview.
Jun 22, 2007 04:27 PM|scampione|LINK
I was able to accomplish this by appending to the SelectCommand of the DataSource.
Protected Sub DetermineSelect()
Dim strSelect as String = getSelectionList()
If strSelect <> "" Then
datasource.SelectCommand += " where " + strSelect
Private Function getSelectionList() As String
Dim tmp As String = ""
Dim I As Integer = 0
For Each li As ListItem In CheckBoxList1.Items
If li.Selected Then
I += 1
If I = 1 Then
tmp += " (selection = '" + li.Value + "' "
tmp += " OR selection = '" + li.Value + "'"
If tmp <> "" Then
tmp += ")"
Jun 24, 2007 02:46 PM|darkknight187|LINK
Thank you for your reply, but it still doesn't work.
Is what you posted a direct copy and paste from your working version.
It seems like I should be putting something in between those ""
Would you mind puting in a direct copy from your code, Then I should be able to get it right.
Jun 25, 2007 10:36 AM|scampione|LINK
Yes it is actually from my working version. Note that in these statements:
tmp += " (selection = '" + li.Value + "' "
tmp += " OR statusid = '" + li.Value + "'"
there is a tic mark along with the quote mark (sort of difficult to see in this font). Here are the same statements with spaces between the quote/tic marks.
tmp += " (selection = " ' + li.Value + ' " "
tmp += " OR statusid = ' " + li.Value + " ' "
there are no tic marks here (also with an extra space between quote marks):
If strSelect <> " " Then datasource.SelectCommand += " where " + strSelect End If
hope that helps.