Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Some background: I have a dropdownlist on a master page that the user can use to select a different area of a business.

On a gridview page I have set up a filter based on some code from the site: http://demo.evonet.com.au/GridviewwithFiltering.aspx[^]

The issue I have is when a user changes the area on the master page the dropdownlist gets populate with the new values for the area and also retains the values from the previous Area.


Example: Area A: AA, AB, AC the dropdownlist will only show those items. when the user selects Area B: BB, BC, BD the drop down will show BB, BC, BD, AA, AB, AC.

How do I prevent this?

Here is the Dropdownlist on the gridview page:
XML
<asp:DropDownList ID="ddlLastName" DataSourceID="SqlDataSource2" AutoPostBack="True"
    DataValueField="LastName" runat="server" Width="120px" Font-Size="11px"
    AppendDataBoundItems="True" DataTextField="LastName">
    <asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
    ConnectionString="<%$ ConnectionStrings:XXXConnectionString %>"
    SelectCommand="SELECT [LastName] FROM [Names] WHERE ([Site] = @Site) ORDER BY [LastName]">
    <SelectParameters>
        <asp:ControlParameter ControlID="TextBox1" Name="Site"
            PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>
Posted

1 solution

Hi

Remove
AppendDataBoundItems="True"
tage from your dropdownlist and try.

Hope this helps.
 
Share this answer
 
Comments
Andy Morris 22-Dec-11 9:05am    
The problem with this is now I need to add the "ALL" to the list. If fixed the issues of the doubling of the data but I need to reset it so every thing will show when "All" is selected.

<asp:ListItem Text="All" Value="%">
Andy Morris 22-Dec-11 9:46am    
I added the following in VB code and it now works:

Private Sub ddlLastName_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlLastName.DataBound
Me.ddlLastName.Items.Insert(0, New ListItem("All", "%"))
End Sub

Private Sub ddlFirstName_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFirstName.DataBound
Me.ddlFirstName.Items.Insert(0, New ListItem("All", "%"))
End Sub
sriman.ch 22-Dec-11 11:18am    
ok happy coding

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900