GridView Filtering?

Last post 06-17-2008 8:08 AM by kjficht. 11 replies.

Sort Posts:

  • GridView Filtering?

    06-11-2008, 2:13 PM
    • Member
      110 point Member
    • kjficht
    • Member since 05-19-2008, 12:22 PM
    • Posts 34

    As many of you may know or perhaps not know when using two filter parameters in a gridview they both must have values for the gridview to work properly so I created a code behind and i was wondering if anyone could help me clean it up. as of right now it works. If you select the first dropdownlist the data is filtered if you select the first and second its filter and if you select just the second its filter

    1    sub BuildFilterExpression(Sender as object, e as eventargs)
    2    	Dim Firstapp = DropDownList1.SelectedValue
    3    	Dim FirstInd = DropDownList2.SelectedValue
    4    	If Firstapp = "" and FirstInd = "" then
    5    		SqlDataSource1.FilterExpression = ""
    6    	Else
    7    		If Firstapp <> "" and FirstInd = "" then
    8    			SqlDataSource1.FilterParameters.Clear()
    9    			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    10   			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    11   			SqlDataSource1.FilterExpression = "First_Application = '{0}'"
    12   		Else
    13   			If SqlDataSource1.FilterParameters("First_Industry") IS Nothing Then
    14   				Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    15   				SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    16   				SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (First_Industry = '{1}')"
    17   			Else
    18   				SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (First_Industry = '{1}')"
    19   			End If
    20   		End If
    21   		
    22   		If Firstapp = "" and FirstInd <> "" then
    23   			SqlDataSource1.FilterParameters.Clear()
    24   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    25   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)	
    26   			SqlDataSource1.FilterExpression = "First_Industry = '{0}'"
    27   		End If
    28   	End If
    29   End Sub
    30   
    
     
    Make sure to click "mark as answer" for post(s) that helped you.
  • Re: GridView Filtering?

    06-11-2008, 4:00 PM
    • Participant
      852 point Participant
    • Gaucho
    • Member since 04-21-2008, 11:54 AM
    • Corona, California
    • Posts 201

    Your solution looks a lot like a similar situation I have been working with recently.  If you check the thread below, you'll see a post by "Gunteman" (which is the code I went with after adding my own tweaks). This code currently works if selections are made in both CheckBoxLists, but now I'm trying to tweak it so that users can make choices in only one or the other CheckBoxList.  I know that NULL values will play a role in the finished code that I go with when all is said and done.  I may look at yours for ideas - thanks for posting it 

     http://forums.asp.net/t/1272956.aspx

  • Re: GridView Filtering?

    06-13-2008, 1:22 PM
    • Member
      110 point Member
    • kjficht
    • Member since 05-19-2008, 12:22 PM
    • Posts 34

     

    1    sub BuildFilterExpression(Sender as object, e as eventargs)
    2    	Dim Firstapp = DropDownList1.SelectedValue
    3    	Dim Secondapp = DropDownList3.SelectedValue
    4    	Dim FirstInd = DropDownList2.SelectedValue
    5    		If Firstapp <> "" and SecondApp = "" and FirstInd = "" then
    6    			SqlDataSource1.FilterParameters.Clear()
    7    			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    8    			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    9    			SqlDataSource1.FilterExpression = "(First_Application = '{0}')"
    10   		End If
    11   
    12   		If Firstapp = "" and SecondApp <> "" and FirstInd = "" then
    13   			SqlDataSource1.FilterParameters.Clear()
    14   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    15   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    16   			SqlDataSource1.FilterExpression = "(Second_Application = '{0}')"
    17   		End If
    18   
    19   		If Firstapp = "" and SecondApp = "" and FirstInd <> "" then
    20   			SqlDataSource1.FilterParameters.Clear()
    21   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    22   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    23   			SqlDataSource1.FilterExpression = "(First_Industry = '{0}')"
    24   		End If
    25   
    26   		If Firstapp <> "" and SecondApp <> "" and FirstInd = "" Then
    27   			SqlDataSource1.FilterParameters.Clear()
    28   			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    29   			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    30   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    31   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    32   			SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (Second_Application = '{1}')"
    33   		End If
    34   
    35   		If Firstapp <> "" and SecondApp = "" and FirstInd <> "" Then
    36   			SqlDataSource1.FilterParameters.Clear()
    37   			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    38   			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    39   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    40   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    41   			SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (First_Industry = '{1}')"
    42   		End If
    43   
    44   		If Firstapp = "" and SecondApp <> "" and FirstInd <> "" Then
    45   			SqlDataSource1.FilterParameters.Clear()
    46   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    47   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    48   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    49   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    50   			SqlDataSource1.FilterExpression = "(Second_Application = '{0}') AND (First_Industry = '{1}')"
    51   		End If
    52   
    53   		If Firstapp <> "" and SecondApp <> "" and FirstInd <> "" Then
    54   			SqlDataSource1.FilterParameters.Clear()
    55   			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    56   			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    57   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    58   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    59   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    60   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    61   			SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (Second_Application = '{1}') AND (First_Industry = '{2}')"
    62   		End If
    63   
    64   End Sub
    65   
    

     i added more do filter with three drop downs know i need help cuz i need to do 6 in the end so anyone want to help reformat this for smaller code there are 7 options here with 6 dropdowns there would have to be 63 of them

    Make sure to click "mark as answer" for post(s) that helped you.
  • Re: GridView Filtering?

    06-13-2008, 2:15 PM
    • Member
      110 point Member
    • kjficht
    • Member since 05-19-2008, 12:22 PM
    • Posts 34

    All 63 permutations

    1    {= ““ ,= ““ ,= ““ ,= ““ ,= ““ ,<> ““ }
    2    {= ““ ,= ““ ,= ““ ,= ““ ,<> ““ ,= ““ }
    3    {= ““ ,= ““ ,= ““ ,= ““ ,<> ““ ,<> ““ }
    4    {= ““ ,= ““ ,= ““ ,<> ““ ,= ““ ,= ““ }
    5    {= ““ ,= ““ ,= ““ ,<> ““ ,= ““ ,<> ““ }
    6    {= ““ ,= ““ ,= ““ ,<> ““ ,<> ““ ,= ““ }
    7    {= ““ ,= ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ }
    8    {= ““ ,= ““ ,<> ““ ,= ““ ,= ““ ,= ““ }
    9    {= ““ ,= ““ ,<> ““ ,= ““ ,= ““ ,<> ““ }
    10   {= ““ ,= ““ ,<> ““ ,= ““ ,<> ““ ,= ““ }
    11   {= ““ ,= ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ }
    12   {= ““ ,= ““ ,<> ““ ,<> ““ ,= ““ ,= ““ }
    13   {= ““ ,= ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ }
    14   {= ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ }
    15   {= ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ }
    16   {= ““ ,<> ““ ,= ““ ,= ““ ,= ““ ,= ““ }
    17   {= ““ ,<> ““ ,= ““ ,= ““ ,= ““ ,<> ““ }
    18   {= ““ ,<> ““ ,= ““ ,= ““ ,<> ““ ,= ““ }
    19   {= ““ ,<> ““ ,= ““ ,= ““ ,<> ““ ,<> ““ }
    20   {= ““ ,<> ““ ,= ““ ,<> ““ ,= ““ ,= ““ }
    21   {= ““ ,<> ““ ,= ““ ,<> ““ ,= ““ ,<> ““ }
    22   {= ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ ,= ““ }
    23   {= ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ }
    24   {= ““ ,<> ““ ,<> ““ ,= ““ ,= ““ ,= ““ }
    25   {= ““ ,<> ““ ,<> ““ ,= ““ ,= ““ ,<> ““ }
    26   {= ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ ,= ““ }
    27   {= ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ }
    28   {= ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ ,= ““ }
    29   {= ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ }
    30   {= ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ }
    31   {= ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ }
    32   {<> ““ ,= ““ ,= ““ ,= ““ ,= ““ ,= ““ }
    33   {<> ““ ,= ““ ,= ““ ,= ““ ,= ““ ,<> ““ }
    34   {<> ““ ,= ““ ,= ““ ,= ““ ,<> ““ ,= ““ }
    35   {<> ““ ,= ““ ,= ““ ,= ““ ,<> ““ ,<> ““ }
    36   {<> ““ ,= ““ ,= ““ ,<> ““ ,= ““ ,= ““ }
    37   {<> ““ ,= ““ ,= ““ ,<> ““ ,= ““ ,<> ““ }
    38   {<> ““ ,= ““ ,= ““ ,<> ““ ,<> ““ ,= ““ }
    39   {<> ““ ,= ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ }
    40   {<> ““ ,= ““ ,<> ““ ,= ““ ,= ““ ,= ““ }
    41   {<> ““ ,= ““ ,<> ““ ,= ““ ,= ““ ,<> ““ }
    42   {<> ““ ,= ““ ,<> ““ ,= ““ ,<> ““ ,= ““ }
    43   {<> ““ ,= ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ }
    44   {<> ““ ,= ““ ,<> ““ ,<> ““ ,= ““ ,= ““ }
    45   {<> ““ ,= ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ }
    46   {<> ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ }
    47   {<> ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ }
    48    {<> ““ ,<> ““ ,= ““ ,= ““ ,= ““ ,= ““ }
    49   {<> ““ ,<> ““ ,= ““ ,= ““ ,= ““ ,<> ““ }
    50   {<> ““ ,<> ““ ,= ““ ,= ““ ,<> ““ ,= ““ }
    51   {<> ““ ,<> ““ ,= ““ ,= ““ ,<> ““ ,<> ““ }
    52   {<> ““ ,<> ““ ,= ““ ,<> ““ ,= ““ ,= ““ }
    53   {<> ““ ,<> ““ ,= ““ ,<> ““ ,= ““ ,<> ““ }
    54   {<> ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ ,= ““ }
    55   {<> ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ ,<> ““ }
    56   {<> ““ ,<> ““ ,<> ““ ,= ““ ,= ““ ,= ““ }
    57   {<> ““ ,<> ““ ,<> ““ ,= ““ ,= ““ ,<> ““ }
    58   {<> ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ ,= ““ }
    59   {<> ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ ,<> ““ }
    60   {<> ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ ,= ““ }
    61   {<> ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ ,<> ““ }
    62   {<> ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ ,= ““ }
    63   {<> ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ ,<> ““ }
    
     
    Make sure to click "mark as answer" for post(s) that helped you.
  • Re: GridView Filtering?

    06-13-2008, 2:15 PM
    • Member
      110 point Member
    • kjficht
    • Member since 05-19-2008, 12:22 PM
    • Posts 34

    it posted twice

    Make sure to click "mark as answer" for post(s) that helped you.
  • Re: GridView Filtering?

    06-13-2008, 3:08 PM
    • Contributor
      3,561 point Contributor
    • mellamokb
    • Member since 02-09-2007, 10:44 PM
    • Posts 644

    Hi,

    You are definitely making this way, way, way too complicated.  Here is my version, but I could make it shorter if I took the time: 

            Dim FirstApp = DropDownList1.SelectedValue
            Dim SecondApp = DropDownList3.SelectedValue
            Dim FirstInd = DropDownList2.SelectedValue
    
            Dim FilterList As List(Of String) = New List(Of String)
            If FirstApp <> "" Then
                FilterList.Add(String.Format("(First_Application = '{0}')", FirstApp))
            End If
            If SecondApp <> "" Then
                FilterList.Add(String.Format("(Second_Application = '{0}')", FirstApp))
            End If
            If FirstInd <> "" Then
                FilterList.Add(String.Format("(First_Industry = '{0}')", FirstApp))
            End If
    
            SqlDataSource1.FilterExpression = String.Join(" AND ", FilterList.ToArray())

      It's easier if you look at one expression at a time instead of all three (or six) at once :)

    Regards,

     ~ mellamokb 

  • Re: GridView Filtering?

    06-13-2008, 4:15 PM
    • Contributor
      3,561 point Contributor
    • mellamokb
    • Member since 02-09-2007, 10:44 PM
    • Posts 644

     Here is a shorter version, using six dropdownlists.  It should be pretty clear that you add to the list by adding to the FieldValueArray dictionary, where the key is the name of the field, and the value is what you are filtering for: 

            Dim FieldValueArray As Dictionary(Of String, String) = New Dictionary(Of String, String)
            FieldValueArray.Add("First_Application", DropDownList1.SelectedValue)
            FieldValueArray.Add("Second_Application", DropDownList2.SelectedValue)
            FieldValueArray.Add("First_Industry", DropDownList3.SelectedValue)
            FieldValueArray.Add("Second_Industry", DropDownList4.SelectedValue)
            FieldValueArray.Add("First_Whatever", DropDownList5.SelectedValue)
            FieldValueArray.Add("Second_Whatever", DropDownList6.SelectedValue)
    
            Dim FilterList As List(Of String) = New List(Of String)
            For Each key As String In FieldValueArray.Keys
                Dim value As String = FieldValueArray(key)
                If Not String.IsNullOrEmpty(value) Then
                    FilterList.Add(String.Format("({0} = '{1}')", key, value))
                End If
            Next
    
            SqlDataSource1.FilterExpression = String.Join(" AND ", FilterList.ToArray())
    

     
    Hope this helps!

    ~ mellamokb 

  • Re: GridView Filtering?

    06-16-2008, 8:59 AM
    • Member
      110 point Member
    • kjficht
    • Member since 05-19-2008, 12:22 PM
    • Posts 34

    ok well i tried both of yours mellamokb and i get an error trying to use both

    Exception Details: System.ArgumentException: Value does not fall within the expected range.

     
    Make sure to click "mark as answer" for post(s) that helped you.
  • Re: GridView Filtering?

    06-16-2008, 10:20 AM
    • Contributor
      3,561 point Contributor
    • mellamokb
    • Member since 02-09-2007, 10:44 PM
    • Posts 644

    And what is the line number for that error message?  I tried both code snippets I gave you with my own dropdownlists, and the filter expression generated seems to be valid.  Is the code required to use FilterParameters in order to function?  If so, it should be pretty easy to make that modification.  Could you maybe post all of your code for this page?

    Regards,

    ~ mellamokb

  • Re: GridView Filtering?

    06-16-2008, 1:35 PM
    • Member
      110 point Member
    • kjficht
    • Member since 05-19-2008, 12:22 PM
    • Posts 34

     

    1    <script runat="server" type="text/vb">
    2    sub Page_Load(Sender as object, e as eventargs)
    3    	Dim Firstapp = DropDownList1.SelectedValue
    4    	Dim Secondapp = DropDownList3.SelectedValue
    5    	Dim FirstInd = DropDownList2.SelectedValue
    6    		If Firstapp <> "" and SecondApp = "" and FirstInd = "" then
    7    			SqlDataSource1.FilterParameters.Clear()
    8    			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    9    			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    10   			SqlDataSource1.FilterExpression = "(First_Application = '{0}')"
    11   		End If
    12   
    13   		If Firstapp = "" and SecondApp <> "" and FirstInd = "" then
    14   			SqlDataSource1.FilterParameters.Clear()
    15   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    16   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    17   			SqlDataSource1.FilterExpression = "(Second_Application = '{0}')"
    18   		End If
    19   
    20   		If Firstapp = "" and SecondApp = "" and FirstInd <> "" then
    21   			SqlDataSource1.FilterParameters.Clear()
    22   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    23   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    24   			SqlDataSource1.FilterExpression = "(First_Industry = '{0}')"
    25   		End If
    26   
    27   		If Firstapp <> "" and SecondApp <> "" and FirstInd = "" Then
    28   			SqlDataSource1.FilterParameters.Clear()
    29   			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    30   			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    31   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    32   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    33   			SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (Second_Application = '{1}')"
    34   		End If
    35   
    36   		If Firstapp <> "" and SecondApp = "" and FirstInd <> "" Then
    37   			SqlDataSource1.FilterParameters.Clear()
    38   			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    39   			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    40   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    41   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    42   			SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (First_Industry = '{1}')"
    43   		End If
    44   
    45   		If Firstapp = "" and SecondApp <> "" and FirstInd <> "" Then
    46   			SqlDataSource1.FilterParameters.Clear()
    47   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    48   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    49   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    50   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    51   			SqlDataSource1.FilterExpression = "(Second_Application = '{0}') AND (First_Industry = '{1}')"
    52   		End If
    53   
    54   		If Firstapp <> "" and SecondApp <> "" and FirstInd <> "" Then
    55   			SqlDataSource1.FilterParameters.Clear()
    56   			Dim cprFirstApp as new ControlParameter("First_Application", "DropDownList1", "SelectedValue")
    57   			SqlDataSource1.FilterParameters.Add(cprFirstApp)
    58   			Dim cprSecondApp as new ControlParameter("Second_Application", "DropDownList3", "SelectedValue")
    59   			SqlDataSource1.FilterParameters.Add(cprSecondApp)
    60   			Dim cprFirstIndustry as new ControlParameter("First_Industry", "DropDownList2", "SelectedValue")
    61   			SqlDataSource1.FilterParameters.Add(cprFirstIndustry)
    62   			SqlDataSource1.FilterExpression = "(First_Application = '{0}') AND (Second_Application = '{1}') AND (First_Industry = '{2}')"
    63   		End If
    64   End Sub
    65   </script>
    66   
    67   Primary Application:<asp:DropDownList runat="server"
    68   	id="DropDownList1"
    69   	DataTextField="Applications"
    70   	DataSourceId="dsAppddl"
    71   	AppendDataBoundItems="True"
    72   	AutoPostBack="True">
    73   	<asp:ListItem Value="">Show All</asp:ListItem>
    74   </asp:DropDownList> 
    75   Secondary Application:<asp:DropDownList runat="server"
    76   	id="DropDownList3"
    77   	DataTextField="Applications"
    78   	DataSourceId="dsAppddl"
    79   	AppendDataBoundItems="True"
    80   	AutoPostBack="True">
    81   	<asp:ListItem Value="">Show All</asp:ListItem>
    82   </asp:DropDownList>
    83   Primary Industry:<asp:DropDownList runat="server"
    84   	id="DropDownList2"
    85   	DataTextField="Industries"
    86   	AutoPostBack="true"
    87   	DataSourceId="dsIndddl"
    88   	AppendDataBoundItems="True">
    89   	<asp:ListItem Value="">Show All</asp:ListItem>
    90   </asp:DropDownList>
    91   
    92   <asp:GridView ID="GridView1"
    93   	AllowSorting="True"
    94   	AllowPaging="True"
    95   	runat="server"
    96   	DataSourceID="SqlDataSource1"
    97   	DataKeyNames="Parent_Company_Name"
    98   	AutoGenerateColumns="False"
    99   	RowStyle-Font-Size="75%">
    100              <RowStyle Font-Size="75%" />
    101              <Columns>
    102                <asp:boundfield DataField="Parent_Company_Name" HeaderText="Parent Company Name" ReadOnly="True" SortExpression="Parent_Company_Name">
    103                  <ItemStyle VerticalAlign="Top" />
    104                </asp:boundfield>
    105                <asp:boundfield DataField="Sales_Person" HeaderText="Sales Person" SortExpression="Sales_Person">
    106                  <ItemStyle VerticalAlign="Top" />
    107                </asp:boundfield>
    108                <asp:boundfield DataField="System_Partner_Level" HeaderText="System Partner Level" SortExpression="System_Partner_Level">
    109                  <ItemStyle VerticalAlign="Top" />
    110                </asp:boundfield>
    111                <asp:boundfield DataField="First_Application" HeaderText="Primary Application" SortExpression="First_Application">
    112                  <ItemStyle VerticalAlign="Top" />
    113                </asp:boundfield>
    114                <asp:boundfield DataField="Second_Application" HeaderText="Secondary Application" SortExpression="Second_Application">
    115                  <ItemStyle VerticalAlign="Top" />
    116                </asp:boundfield>
    117                <asp:boundfield DataField="First_Industry" HeaderText="Primary Industry" SortExpression="First_Industry">
    118                  <ItemStyle VerticalAlign="Top" />
    119                </asp:boundfield>
    120                <asp:hyperlinkfield DataNavigateUrlFields="Parent_Company_Name" DataNavigateUrlFormatString="viewcompany.aspx?CompName={0}" Text="View/Edit">
    121                  <ItemStyle HorizontalAlign="Center" />
    122                </asp:hyperlinkfield>
    123              </Columns>
    124              <EmptyDataTemplate>
    125                <table cellspacing="0" rules="all" style="border-collapse:collapse;">
    126                	<tr>
    127                		<td class="ms-toolbar">Parent Company Name</td>
    128                		<td class="ms-toolbar">Sales Person</td>
    129                		<td class="ms-toolbar">System Partner Level</td>
    130                		<td class="ms-toolbar">Primary Application</td>
    131                		<td class="ms-toolbar">Secondary Application</td>
    132                		<td class="ms-toolbar">Primary Industry</td>
    133                	</tr>
    134                	<tr>
    135                		<td colspan="6" align="center" style="font-size:75%">No records to display.</td>
    136                	</tr>
    137                </table>
    138              </EmptyDataTemplate>
    139            </asp:GridView>
    140            <br />
    141              | 
    142  			<asp:HyperLink ID="HyperLink1" Text="Add New Company" NavigateUrl="addcompany.aspx" runat="server"/> |
    143            <asp:HyperLink ID="HyperLink2" Text="Upload Company Logo" NavigateUrl="/Sales/_layouts/Upload.aspx?List={F9A746AB-D565-4C11-A076-491748FD6FC9}" runat="server"/> |
    144  
    145            <asp:SqlDataSource ID="SqlDataSource1"
    146              runat="server"
    147              providerName="System.Data.OleDb"
    148              EnableCaching="True"
    149              ConnectionString="<%$ ConnectionStrings:SystemPartnerDatabase %>"
    150              CacheDuration="20"
    151              CacheExpirationPolicy="Absolute"
    152              SelectCommand="SELECT [Parent_Company_Name], [Sales_Person], [System_Partner_Level],
    153              				[First_Application], [Second_Application], [First_Industry],
    154              				FROM [SYSTEM PARTNER DATABASE$] WHERE [Parent_Company_Name] IS NOT NULL">
    155            <FilterParameters>
    156              	<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" />
    157            </FilterParameters>
    158            </asp:SqlDataSource>
    159  
    160            <asp:SqlDataSource
    161              runat="server"
    162              id="dsAppddl"
    163              providerName="System.Data.OleDb"
    164              ConnectionString="<%$ ConnectionStrings:SystemPartnerDatabase %>"
    165              SelectCommand="SELECT DISTINCT * FROM [applications]">
    166            </asp:SqlDataSource>
    167  
    168            <asp:SqlDataSource
    169              runat="server"
    170              id="dsIndddl"
    171              providerName="System.Data.OleDb"
    172              ConnectionString="<%$ ConnectionStrings:SystemPartnerDatabase %>"
    173              SelectCommand="SELECT DISTINCT * FROM [Industries]">
    174            </asp:SqlDataSource>
    
     
    Make sure to click "mark as answer" for post(s) that helped you.
  • Re: GridView Filtering?

    06-16-2008, 10:41 PM
    • Contributor
      3,561 point Contributor
    • mellamokb
    • Member since 02-09-2007, 10:44 PM
    • Posts 644

    Hi,

    I noticed I had them in the order DropDownList1, DropDownList2, DropDownList3, whereas you had them in the order DropDownList1, DropDownList3, DropDownList2.  That might be where your exception came from.  Anyway, I have copied your code, and constructed some sample tables matching your data layout, and the following code worked perfectly for me using your source: 

                Dim FieldValueArray As Dictionary(Of String, String) = New Dictionary(Of String, String)
                Dim filterIndex As Integer = 0
                FieldValueArray.Add("First_Application", "DropDownList1")
                FieldValueArray.Add("Second_Application", "DropDownList3")
                FieldValueArray.Add("First_Industry", "DropDownList2")
    
                Dim FilterList As List(Of String) = New List(Of String)()
                Dim ddl As DropDownList
                For Each key As String In FieldValueArray.Keys
                    Dim value As String = FieldValueArray(key)
                    ddl = DirectCast(Page.FindControl(value), DropDownList)
                    If Not String.IsNullOrEmpty(ddl.SelectedValue) Then
                        If filterIndex = 0 Then
                            SqlDataSource1.FilterParameters.Clear()
                        End If
                        Dim cpr As ControlParameter = New ControlParameter(key, ddl.ID, "SelectedValue")
                        SqlDataSource1.FilterParameters.Add(cpr)
                        FilterList.Add(String.Format("({0} = '{{{1}}}')", key, filterIndex.ToString()))
                        filterIndex += 1
                    End If
                Next
    
                SqlDataSource1.FilterExpression = String.Join(" AND ", FilterList.ToArray())

     Please let me know how this works for you!

    Regards,

    ~ mellamokb

  • Re: GridView Filtering?

    06-17-2008, 8:08 AM
    • Member
      110 point Member
    • kjficht
    • Member since 05-19-2008, 12:22 PM
    • Posts 34

    im sry you can just stop trying to help if you want because it dont work

    Exception Details: System.ArgumentException: Value does not fall within the expected range.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentException: Value does not fall within the expected range.]
       System.Web.Hosting.VirtualPathProvider.GetFileWithCheck(String virtualPath) +11
       System.Web.FormatterWithFileInfo.GetSourceFileLines(String fileName, Encoding encoding, String sourceCode, Int32 lineNumber) +229
       System.Web.DynamicCompileErrorFormatter.get_MiscSectionContent() +926
       System.Web.ErrorFormatter.GetHtmlErrorMessage(Boolean dontShowSensitiveInfo) +818
       System.Web.HttpResponse.WriteErrorMessage(Exception e, Boolean dontShowSensitiveErrors) +645
       System.Web.HttpResponse.ReportRuntimeError(Exception e, Boolean canThrow, Boolean localExecute) +271
       System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e) +338
    

    Make sure to click "mark as answer" for post(s) that helped you.
Page 1 of 1 (12 items)