<pre lang="xml">Im very new and have found a solution which filter with on e grid but how do I manaipulate the Vb code to accomodate anothe industry filter.
here's my ASP current code
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource2"
ForeColor="#333333" GridLines="None" DataKeyNames="Permit_No"
Width="798px">
<RowStyle BackColor="lightgrey" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="Permit_No" HeaderText="Permit_No" SortExpression="Permit_No" />
<asp:HyperLinkField runat="server" DataTextField="Name" DataNavigateUrlFields="Permit_No,Name,Postal,Street,Tel,Fax,Cell,Website_Address,"
DataNavigateUrlFormatString="Default2.aspx?ID={0}&Name={1}&Pos={2}&Physical={3}&Phone={4}&PhoneFax={5}&CellPhone={6}&Web={7}" HeaderText="Name" />
<asp:BoundField DataField="Spec_No" HeaderText="Spec_No"
SortExpression="Spec_No" />
<asp:BoundField DataField="Tel" HeaderText="Tel" SortExpression="Tel" />
<asp:TemplateField HeaderText="Region" SortExpression="Region">
<HeaderTemplate>
Region
<asp:DropDownList ID="ddRegion"
DataTextField="Region"
AutoPostBack="true"
OnSelectedIndexChanged="FilterDropDown_IndexChanged"
OnPreRender="SetValue"
DataSourceID="RegionDataSource" runat="server"/>
</HeaderTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Region") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Region") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Industry" SortExpression="Industry">
<HeaderTemplate>
Industry
<asp:DropDownList ID="ddIndustry"
DataTextField="Industry"
AutoPostBack="true"
OnSelectedIndexChanged="FilterDropDown_IndexChanged"
OnPreRender="SetValue"
DataSourceID="IndustryDataSource" runat="server"/>
</HeaderTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Industry") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Industry") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Industry" HeaderText="Industry"
SortExpression="Industry" />
<asp:HyperLinkField />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="red" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="red" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
VB<NET Code
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If SearchList.SelectedItem.Value = "1" Then
GridView1.Visible = True
GridView2.Visible = False
GridView3.Visible = False
GridView4.Visible = False
ElseIf SearchList.SelectedItem.Value = "2" Then
GridView1.Visible = False
GridView2.Visible = True
GridView3.Visible = False
GridView4.Visible = False
ElseIf SearchList.SelectedItem.Value = "3" Then
GridView1.Visible = False
GridView2.Visible = False
GridView3.Visible = True
GridView4.Visible = False
ElseIf SearchList.SelectedItem.Value = "4" Then
GridView1.Visible = False
GridView2.Visible = False
GridView3.Visible = False
GridView4.Visible = True
End If
End Sub
Private filter As New Hashtable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'searchTextBox.Text = ""
filter = If(ViewState("FilterArgs") Is Nothing, New Hashtable(), DirectCast(ViewState("FilterArgs"), Hashtable))
End Sub
Protected Sub FilterDropDown_IndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim dd As DropDownList = DirectCast(sender, DropDownList)
Dim ddIndustry = DirectCast(sender, DropDownList)
If dd.SelectedItem.Text <> "ALL Regions" Then
If filter.ContainsKey("Region") Then
filter("Region") = "='" & dd.SelectedItem.Text & "'"
Else
filter.Add("Region", "='" & dd.SelectedItem.Text & "'")
End If
Else
filter.Remove("Region")
End If
If dd.SelectedItem.Text <> "ALL Industry" Then
If filter.ContainsKey("Industry") Then
filter("Industry") = "='" & ddIndustry.SelectedItem.Text & "'"
Else
filter.Add("Industry", "='" & ddIndustry.SelectedItem.Text & "'")
End If
Else
filter.Remove("Industry")
End If
ApplyGridFilter()
GridView2.PageIndex = 0
End Sub
Protected Sub ApplyGridFilter()
Dim args As String = " "
Dim i As Integer = 0
For Each key As Object In filter.Keys
If i = 0 Then
args = key.ToString() + filter(key).ToString()
Else
args += (" AND " & key.ToString()) + filter(key).ToString()
End If
i += 1
Next
SqlDataSource2.FilterExpression = args
'Filter needs to be saved between postbacks
ViewState.Add("FilterArgs", filter)
End Sub
Protected Sub SetValue(ByVal sender As Object, ByVal e As EventArgs)
Dim ddl As DropDownList = DirectCast(sender, DropDownList)
Dim ddlIndustry As DropDownList = DirectCast(sender, DropDownList)
If filter IsNot Nothing Then
If filter.ContainsKey("Region") Then
For Each li As ListItem In ddl.Items
If li.Text = filter("Region").ToString().Substring(2, filter("Region").ToString().Length - 3) Then
li.Selected = True
Exit Sub
End If
Next
End If
Else
If filter.ContainsKey("Industry") Then
For Each li As ListItem In ddl.Items
If li.Text = filter("Industry").ToString().Substring(2, filter("Industry").ToString().Length - 3) Then
li.Selected = True
Exit Sub
End If
Next
End If
End If
End Sub
Protected Sub GridView2_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
ApplyGridFilter()
End Sub
'Protected Sub btnRemoveFilter_Click(ByVal sender As Object, ByVal e As EventArgs)
' 'ViewState.Remove("FilterArgs");
' filter.Clear()
' ApplyGridFilter()
'End Sub
Please assist i have been trying without sucess</pre>