CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.classifieds_starter_kit Tags:
Item Type: NewsGroup Date Entered: 6/14/2007 1:59:45 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 9 Views: 709 Favorited: 0 Favorite
10 Items, 1 Pages 1 |< << Go >> >|
darkknight187
Asp.Net User
How can I filter my gridview results with a checkbox list?6/14/2007 1:59:45 AM

0

Hello all;

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.

<asp:CheckBoxList ID="AdTypeList" runat="server" RepeatDirection="Horizontal"

Width="350px" CssClass="style9">

<asp:ListItem Value="1">Box1</asp:ListItem>

<asp:ListItem Value="2">Box2</asp:ListItem>

<asp:ListItem Value="3">Box3</asp:ListItem>

</asp:CheckBoxList>

 

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

 


Be sure to visit www.detelli.com

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
Prashant Kumar
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/14/2007 3:48:47 AM

0

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. 


Regards,
Prashant


Dont forget to click "Mark as Answer" on the post that helped you.
darkknight187
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/15/2007 1:52:28 AM

0

I have tried many variations, but no luck.

Can you give me an example of VB code for it?


Be sure to visit www.detelli.com

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
darkknight187
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/17/2007 1:49:05 AM

0

Does anyone have any ideas how to do this?


Be sure to visit www.detelli.com

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
Prashant Kumar
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/17/2007 6:15:37 AM

0

 Please post your code and I'll help you fix it.


Regards,
Prashant


Dont forget to click "Mark as Answer" on the post that helped you.
darkknight187
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/17/2007 3:12:28 PM

0

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.

Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click

Dim s As String = "Selected items:<br>"

Dim i As Int32

For i = 0 To AdTypeList.Items.Count - 1

If AdTypeList.Items(i).Selected Then

' List the selected items

s = s & AdTypeList.Items(i).Text

s = s & "<br>"

End If

Next

Label1.Text = s

End Sub

But I cannot get it into the search results. ("AdTypeList" is the checkboxlist control)

 <asp:ObjectDataSource ID="AdSearchDataSource" runat="server" TypeName="AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdsDB"

SelectMethod="GetActiveAdsByQuery" OldValuesParameterFormatString="original_{0}">

<SelectParameters>

<asp:Parameter Type="Int32" DefaultValue="50" Name="recordLimit"></asp:Parameter>

<asp:ControlParameter Name="categoryId" DefaultValue="0" Type="Int32" ControlID="CategoryDropDown"

PropertyName="CurrentCategoryId"></asp:ControlParameter>

<asp:ControlParameter Name="memberId" ControlID="AdvancedSearch" PropertyName="MemberId"

Type="Int32" DefaultValue="0" />

<asp:ControlParameter Name="maxPrice" ControlID="AdvancedSearch" PropertyName="MaximumPrice"

Type="Decimal" DefaultValue="-1" />

<asp:ControlParameter Name="searchTerm" DefaultValue="" Type="String" ControlID="SearchTermTextBox"

PropertyName="Text"></asp:ControlParameter>

<asp:ControlParameter Name="location" ControlID="AdvancedSearch" PropertyName="Location"

Type="String" DefaultValue="" />

<asp:ControlParameter Name="adType" ControlID="AdTypeList" Type="Int32" DefaultValue="0" />

<asp:Parameter Type="Int32" DefaultValue="0" Name="adLevel"></asp:Parameter>

<asp:ControlParameter Name="dayRange" ControlID="AdvancedSearch" PropertyName="DayRange"

Type="Int32" DefaultValue="-1" />

<asp:ControlParameter Name="mustHaveImage" ControlID="AdvancedSearch" PropertyName="MustHavePhotos"

Type="Boolean" DefaultValue="False" />

<asp:ControlParameter ControlID="PriceToDropDown" DefaultValue="-1" Name="PriceTo" Type="Decimal" />

<asp:ControlParameter ControlID="PriceFromDropDown" DefaultValue="-1" Name="PriceFrom" Type="Decimal" />

<asp:ControlParameter ControlID="BedsQuerryDropDown" DefaultValue="-1" Name="BedsQuerry" Type="Decimal" />

<asp:ControlParameter ControlID="BathsQuerryDropDown" DefaultValue="-1" Name="BathsQuerry" Type="Decimal" />

</SelectParameters>

</asp:ObjectDataSource>

 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.

Thanks again

 


Be sure to visit www.detelli.com

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
Prashant Kumar
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/18/2007 2:57:30 PM

0

 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.

http://forums.asp.net/1021.aspx 

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. 


Regards,
Prashant


Dont forget to click "Mark as Answer" on the post that helped you.
scampione
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/22/2007 8:27:39 PM

0

 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
       End If
       ...........
    End Sub




    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 + "' "
                Else
                    tmp += " OR selection = '" + li.Value + "'"
                End If
            End If
        Next
        If tmp <> "" Then
            tmp += ")"
        End If
        Return tmp
    End Function

darkknight187
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/24/2007 6:46:35 PM

0

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.

Thank you


Be sure to visit www.detelli.com

And please remember to click ?Mark as Answer? on the post that helps you.
This can be beneficial to other community members reading the thread.
scampione
Asp.Net User
Re: How can I filter my gridview results with a checkbox list?6/25/2007 2:36:22 PM

0

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.
	
 
10 Items, 1 Pages 1 |< << Go >> >|


Free Download:




   
  Privacy | Contact Us
All Times Are GMT