无法从 Datagrid C# 中的下拉列表中删除项
本文关键字:下拉列表 删除 Datagrid | 更新日期: 2024-11-08 18:22:27
public static Dictionary<int, string> GetCategorySubDivisionDesc()
{
Dictionary<int, string> values = new Dictionary<int, string>();
values.Add(0, "Please select");
values.Add(1, "Whole Property Wanted");
values.Add(2, "Flatshares & Rooms Wanted");
values.Add(3, "Whole Properties Available To Rent");
values.Add(4, "Flatshares & Rooms Available To Rent");
values.Add(5, "Looking for Professional Space to Rent/Share");
//values.Add(6, "Looking for Professional Space to Share");
values.Add(7, "Looking for Professional Space to Buy");
values.Add(8, "Practices Wanted to Buy");
return values;
}
Dictionary<int, string> CategorySubDivisionValues = Enums.GetCategorySubDivisionDesc();
我需要在数据网格中使用这些值的下拉列表,因此我_ItemDataBound事件中的每个下拉列表绑定它
DropDownList cboSpaceCategory = (DropDownList)e.Item.FindControl("cboSpaceCategory");
cboSpaceCategory.DataSource = CategorySubDivisionValues;
cboSpaceCategory.DataTextField = "Value";
cboSpaceCategory.DataValueField = "Key";
cboSpaceCategory.DataBind();
cboSpaceCategory.Items.Remove("Practices Wanted to Buy"); // not working
cboSpaceCategory.Items.RemoveAt(int.Parse(cboSpaceCategory.Items.FindByText("Practices Wanted to Buy").Value)); // not working
但是,这不会删除该项目。请建议任何删除项目的方法。
这样做怎么样。
ListItem itemToRemove = cboSpaceCategory.Items.FindByText("Practices Wanted to Buy");
cboSpaceCategory.Items.Remove(itemToRemove);