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();
我需要使用这些值在datagrid中下拉,所以我为_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
然而,这不会删除该项目。请建议删除项目的任何方法。
答案 0 :(得分:0)
这样做。
ListItem itemToRemove = cboSpaceCategory.Items.FindByText("Practices Wanted to Buy");
cboSpaceCategory.Items.Remove(itemToRemove);