Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate items in dropdownlist!
    primarykey
    data
    text
    <p>Ok I really hope you guys can help me with this, I've spent the past 2 days trying to figure it out and I think I'm about to throw my computer out the window, so I thought I might as well ask here first:</p> <p>I'm designing a web page with two dropdownlists, one for the Make of a car, the other for the Model, both bound to a database with separate SQLDataSources, and using a distinct statement. I add "All" at the top of both by setting appendDataBoundItems = true and adding items named all. Then when I fill the Make with a querystring all the model items get added twice (but only the databound items).</p> <p>Here's my code:</p> <pre><code> &lt;asp:DropDownList ID="DropDownMake" runat="server" DataSourceID="SqlMakes" DataTextField="Make" DataValueField="Make" AppendDataBoundItems="True" EnableViewState="False" AutoPostBack="True"&gt; &lt;asp:ListItem Selected="True" Value="All"&gt;All&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;asp:DropDownList ID="DropDownModel" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlModels" DataTextField="Model" DataValueField="Model" EnableViewState="False"&gt; &lt;asp:ListItem&gt;All&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;asp:SqlDataSource ID="SqlMakes" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" SelectCommand="SELECT DISTINCT [Make] FROM [Parts]"&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:SqlDataSource ID="SqlModels" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" SelectCommand="SELECT DISTINCT [Model] FROM [Parts] WHERE ([Make] = @Make)"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="DropDownMake" Name="Make" PropertyName="SelectedValue" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>'And in the VB file:</p> <pre><code>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 </code></pre> <p>If I remove the line "DropDownMake.SelectedValue = Request.QueryString("Make")" it doesnt produce duplicates anymore. What is going on?? I swear I've spent more time developing entire iphone apps, if anyone helps figure this out I think I'm going to have to make an award for you.</p> <p>Thank you!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload