Can I populate multiple DropDownLists from one SqlDataSource using parameters?
Posted
by death_au
on Stack Overflow
See other posts from Stack Overflow
or by death_au
Published on 2010-06-07T03:03:05Z
Indexed on
2010/06/07
3:12 UTC
Read the original article
Hit count: 329
Basically, I have four asp:DropDownLists and I wish to populate all of them from the same table, with certain conditions.
For example, I have this data source:
<asp:SqlDataSource ID="ReferenceDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:mrapConnectionString1 %>
SelectCommand="SELECT * FROM [reference_data] WHERE ([component] = @component)" >
<SelectParameters>
<asp:Parameter DefaultValue="MB" Name="component" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
And I want to know if I can change that component parameter to be different for each of my four dropdown lists.
I tried adding the following code on the DataBinding event for my DropDown:
ReferenceDataSource1.SelectParameters.Remove(ReferenceDataSource1.SelectParameters["component"]);
ReferenceDataSource1.SelectParameters.Add("component", "MB");
But I ironically got a StackOverflowException...
© Stack Overflow or respective owner