up vote 0 down vote favorite

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...

flag

1  
lol... Got to love irony!! – ggonsalv Jun 7 at 3:06
if you can set the id of your dropdown lists = "component" (MB,etc) you could use a control parameter on the data source with PropertyName=ID – Claudio Redi Jun 7 at 3:33
Claudio, that still requires me to set the control to use, and it could be one of four controls. However, I was not aware I could do that, and I'm sure that's going to come in handy for something else I'm doing, so thanks. – death_au Jun 7 at 4:26
yes, you're right. Sorry man. I made up a feature of ControlParameter. I have to stop answering so late in the night :-( – Claudio Redi Jun 7 at 12:10

Your Answer

get an OpenID
or
never shown

Browse other questions tagged or ask your own question.