vb.net 带有 DropDownList 控制参数的 SqlDataSource 不读取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15579167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:56:12  来源:igfitidea点击:

SqlDataSource with DropDownList Control Parameter doesn't read value

asp.netvb.netdata-bindingsqldatasource

提问by LukeGeneva

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

我有一个绑定到 SqlDataSource 的下拉列表。

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

我有另一个绑定到不同 SqlDataSource 的下拉列表。

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

第二个 SqlDataSource 将第一个下拉列表作为控制参数。

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:

但我没有得到任何结果。但是,如果我将第二个 SqlDataSource 的控制参数设置为文本框,它就可以工作。例如,这有效:

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

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

Any ideas why this is?

任何想法这是为什么?

采纳答案by LukeGeneva

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.

我使用了 Joel Etherton 提出的建议,现在效果很好。虽然我使用了隐藏控件而不是标签。