如何在ASP中添加禁用字段.净dropdownList
本文关键字:字段 dropdownList 添加 ASP | 更新日期: 2023-09-27 18:15:34
我需要在下拉列表中添加可选字段"Select…"。数据与后台代码中的数据库一起绑定。我已经尝试添加禁用字段,但我可以看到任何结果。
背后的代码AvailableRolesList = RoleDefinationRelay.GetAllRoles(null);
ddlRolesList.DataSource = AvailableRolesList;
ddlRolesList.DataTextField = "Title";
ddlRolesList.DataValueField = "RoleID";
ddlRolesList.DataBind();
DropdownList)<asp:DropDownList ID="ddlRolesList" runat="server">
<asp:ListItem Text="SelectRole" Enabled="false" Selected="True">Select Role</asp:ListItem>
</asp:DropDownList>
此处输入代码
您需要在代码后面的绑定下拉列表后添加Select item
AvailableRolesList = RoleDefinationRelay.GetAllRoles(null);
ddlRolesList.DataSource = AvailableRolesList;
ddlRolesList.DataTextField = "Title";
ddlRolesList.DataValueField = "RoleID";
ddlRolesList.DataBind();
ddlRolesList.Items.Insert(0, "Select Role");
这是我的答案
ddlRolesList.Items.Insert(0, new ListItem("Select Role","NA"));