gpt4 book ai didi

c# - 如何使用 C# 绑定(bind) .aspx 中定义的现有下拉列表

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

我在设计页面中有一个下拉列表,如下所示:

<asp:DropDownList ID="ddlArtList" runat="server">
<asp:ListItem Value="95">Select</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
</asp:DropDownList>

根据需要,上述项目有时会被 C# 中的某些其他值覆盖。但最后我想在 C# 的帮助下绑定(bind)上面的默认项以获取上面的列表项。

我想知道在 C# 中是否有任何内置方法或属性来绑定(bind)下拉列表 (.aspx)。

不使用这个:ddlArtList.Items.Add ("1); 等等。

提前致谢。

最佳答案

使用AppendDataBoundItems

.aspx代码:

<asp:DropDownList ID="ddlArtList" AppendDataBoundItems="True" runat="server">
<asp:ListItem Value="95">Select</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
</asp:DropDownList>

服务器端:

ddlArtList.AppendDataBoundItems="True"

关于c# - 如何使用 C# 绑定(bind) .aspx 中定义的现有下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27729697/

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