【问题标题】:can not remove item from a dropdownlist in datagrid c#无法从datagrid c#中的下拉列表中删除项目
【发布时间】:2015-03-10 14:24:16
【问题描述】:
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

但是,这不会删除该项目。请提出任何删除项目的方法。

【问题讨论】:

  • 是wpf还是winforms什么的

标签: c# dictionary datagrid


【解决方案1】:

这样做怎么样。

ListItem itemToRemove = cboSpaceCategory.Items.FindByText("Practices Wanted to Buy");
cboSpaceCategory.Items.Remove(itemToRemove);

【讨论】:

    猜你喜欢
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多