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

标签 c# asp.net .net drop-down-menu c#-3.0

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

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

相关文章:

c# - SaveFileDialog 使 c# 中的 streamwriter 出现问题

c# - 如何在 c# 中使用文件上传控件的内容类型属性(不检查扩展名)来验证上传的文件是否为 csv?

javascript - 握手期间 ASP.NET Core WebSocket 失败

java - 球围绕 3D 球体运动

C# 在鼠标事件上绘制矩形

.net - 如何确定 Treeview 何时完成加载?

asp.net - 在上下文中未找到owin.Environment项目

c# - 删除 IE 中的 cookie 错误?

asp.net - Microsoft.Data.Edm 与 Microsoft.OData.Edm : what is the difference?

c# - 是否有可能知道 JPEG 图像是否仅从其原始字节旋转?