Well, I really hope you guys can help with this, I spent the last 2 days trying to figure it out, and I think I'm going to throw my computer out of the window, so I thought I might ask first:
I am developing a web page with two dropdownlists, one for Make of a car, the other for a model, bound to a database with separate SQLDataSources and using a separate statement. I add "All" at the top of both, setting appendDataBoundItems = true and adding elements called all. Then, when I populate Make with querystring, all model elements are added twice (but only data elements).
Here is my code:
<asp:DropDownList ID="DropDownMake" runat="server" DataSourceID="SqlMakes" DataTextField="Make" DataValueField="Make" AppendDataBoundItems="True" EnableViewState="False" AutoPostBack="True"> <asp:ListItem Selected="True" Value="All">All</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownModel" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlModels" DataTextField="Model" DataValueField="Model" EnableViewState="False"> <asp:ListItem>All</asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="SqlMakes" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Make] FROM [Parts]"> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlModels" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Model] FROM [Parts] WHERE ([Make] = @Make)"> <SelectParameters> <asp:ControlParameter ControlID="DropDownMake" Name="Make" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource>
'And in the VB file:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init DropDownMake.SelectedValue = Request.QueryString("Make") DropDownModel.SelectedValue = Request.QueryString("Model") End Sub
If I delete the line "DropDownMake.SelectedValue = Request.QueryString (" Make "), it will no longer play duplicates. What happens ?? I swear I spent more time developing applications for the iphone, if anyone helps to figure it out, I I think I’ll have to make a reward for you.
Thanks!
source share