1

I have a drop down list that bound to a SqlDataSource.

I have another drop down list that's bound to a different SqlDataSource.

The second SqlDataSource has the first drop down as a Control Parameter.

I'm trying to do this...

<asp:SqlDataSource ID="sqlDataSource2" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT * FROM Test WHERE Param = @param;"
    CancelSelectOnNullParameter="true">
    <SelectParameters>
        <asp:ControlParameter ControlID="dropDown1" Name="param"
            PropertyName="SelectedValue"
            ConvertEmptyStringToNull="true" />
    </SelectParameters>
</asp:SqlDataSource>

dropDown1.SelectedValue = "someValue"
dropDown2.DataBind()

but I don't get any results. However, if I set the second SqlDataSource's Control Parameter to a text box, it works. For example, this works:

<asp:ControlParameter ControlID="txt" Name="param"
    PropertyName="Text"
    ConvertEmptyStringToNull="true" />

txt.Text = "someValue"
dropDown2.DataBind()

Any ideas why this is?

1
  • are you sure you have your datatextfield and datavaluefield arranged properly? Plus do you have autopostback set to true for both controls? Commented Mar 22, 2013 at 23:31

1 Answer 1

1

I ended up figuring this one out. The problem was that the drop down was attempting to bind twice, much like the problem in this question.

I used the suggestion made by Joel Etherton, and now it works perfectly. Although I used a hidden control rather than a label.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.