c# - 向下拉列表框添加新值

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

我有一个下拉列表框,其中一个值是其他值。我想把这些值移到最后。请在这件事上给予我帮助。我使用的代码如下

ddlAssetsCountryOthersone.DataSource = lstIMAssetsByCountryOthers;
ddlAssetsCountryOthersone.DataTextField = "AssetDescription";
ddlAssetsCountryOthersone.DataValueField = "AssetDescription";
ddlAssetsCountryOthersone.DataBind();
ddlAssetsCountryOthersone.Items.Remove(
             ddlAssetsCountryOthersone.Items.FindByValue(
                Constants.PhilosophyAndEmphasis.Other.ToString()));

如何将其他人添加回最后的下拉列表

最佳答案

在你的数据绑定(bind)之后试试这个:

ddlAssetsCountryOthersone.Items.Add(new ListItem("Others", "Others"));

顺便说一句,如果你使用Insert方法,你可以将你想要的项目插入到你想要的位置。例如,下面的代码将 Other 选项添加到第四顺序:

ddlAssetsCountryOthersone.Items.Insert(4, new ListItem("Others", "Others"));

关于c# - 向下拉列表框添加新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1741736/

相关文章:

c# - Blazor - 将参数传递给父级

c# - 反射参数名称 : abuse of C# lambda expressions or syntax brilliance?

c# - MVVM:异步事件处理程序的单元测试

c# - 从批处理文件中获取退出代码

.NET WPF 窗口淡入淡出动画

c# - 如何在 Sharepoint 多行字段中插入新行?

MySQL 选择响应大小 .NET

asp.net - 一种在 ASP.NET 中生成图像签名或哈希值以进行重复检测的方法?

c# - 处理 session 变量超时

c# - 在其他选项 services.Configure<>() 内绑定(bind)选项