gpt4 book ai didi

c# - 如何使用 SQL Server 存储过程填充组合框

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:49 25 4
gpt4 key购买 nike

使用:asp.net 和 C#

我正在尝试使用 SQL Server 存储过程中的值填充组合框。我有组合框加载和工作,但我不知道如何使值显示为下拉列表供客户选择。 ListItem 是否也是加载下拉菜单的正确方法?

这是我目前所拥有的:

.aspx页面:

<asp:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ComboBox ID="ComboBox1" runat="server" DataSourceID="SQL"
DataTextField="DataText" DataValueField="DataValue" MaxLength="0"
style="display: inline;">
<asp:ListItem Value="0">Please Choose an Item......</asp:ListItem>
//What do I put here to load and display the stored procedure in a list
</asp:ComboBox>
<asp:SqlDataSource ID="SQL1" runat="server"
ConnectionString="<%$ CompanyConnectionString %>"
SelectCommand="CompanyStoredProcedure" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="ParameterID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:ToolkitScriptManager>

最佳答案

你的 <asp:Parameter Name="ParameterID" Type="Int32" />没有填充值,这就是为什么你的 ComboBox没有被填充。

您可以:

在后面的代码中以编程方式填充:

protected function Page_Load(object sender, EventArgs e)
{
SQL1.SelectParameters["ParameterID"].DefaultValue = 12;
ComboBox1.DataSource = SQL1.Select(DataSourceSelectArguments.Empty);
ComboBox1.DataBind();
}

或者您可以将其设为 <asp:SessionParameter><asp:ControlParameter Name="ParameterID" Type=Int32" ...

也就是说,将其链接到 Session值或 Asp.NET Control .

关于c# - 如何使用 SQL Server 存储过程填充组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18446887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com