C# 添加一个';残疾人士';类别到下拉列表Webforms

C# 添加一个';残疾人士';类别到下拉列表Webforms,c#,asp.net,webforms,C#,Asp.net,Webforms,我有一个下拉列表,它从数据库中的类别按程序生成“护理项目”,但当一个护理项目(或其类别)被禁用时,我希望在下拉列表的末尾有一个--disabled--category标记,然后填充禁用的内容 下拉框 -饮食 ---餐饮助理 ---食物运送 -卫生 ---沐浴辅助 ---洗衣房 -----------残废------------ -饮食 ---膳食准备 -药 ---饭前服用避孕药 等等 aspx: 护理项目: 政务司司长: public List<CareItemView> GetC

我有一个下拉列表,它从数据库中的类别按程序生成“护理项目”,但当一个护理项目(或其类别)被禁用时,我希望在下拉列表的末尾有一个--disabled--category标记,然后填充禁用的内容

下拉框

-饮食

---餐饮助理

---食物运送

-卫生

---沐浴辅助

---洗衣房

-----------残废------------

-饮食

---膳食准备

-药

---饭前服用避孕药

等等

aspx:

护理项目: 政务司司长:

public List<CareItemView> GetCareItems(long facilityId, long careProgramId, bool includeDisabled = true)
{
    if (facilityId > 0 && SecurityContext.RestrictedFacilityIds != null && !SecurityContext.RestrictedFacilityIds.Contains(facilityId))
    {
        return null;
    }

    var query = CareItemFactory.Instance.GetByCareProgram(facilityId, careProgramId);

    if (!includeDisabled)
    {
        query = query.Where(x => !x.IsDisabled && !x.CareItemCategory.IsDisabled);
    }
    return query.Select(i => new CareItemView
    {
        ID = i.ID,
        Category = i.CareItemCategory.Name,
        Name = i.Name
    }).ToList();
}
public List GetCareItems(long facilityId、long careProgramId、bool includeDisabled=true)
{
如果(facilityId>0&&SecurityContext.RestrictedFacilityId!=null&&SecurityContext.RestrictedFacilityId.Contains(facilityId))
{
返回null;
}
var query=careeItemFactory.Instance.GetByCareProgram(facilityId,careProgramId);
如果(!includeDisabled)
{
query=query.Where(x=>!x.IsDisabled&&!x.careeItemCategory.IsDisabled);
}
返回query.Select(i=>newcareeItemView
{
ID=i.ID,
Category=i.careeItemCategory.Name,
Name=i.名称
}).ToList();
}

在Webforms中实现这一点的最佳方法是什么?我可以在我的查询中实现这一点吗?是的,我知道今年是哪一年,顺便说一句,该死的网络表单。

你可以通过编程在给定的索引中添加列表项

DropDownList1.Items.Insert(5, new ListItem() { Text = "--- Disabled ---", Value = "" });
唯一的问题是,这是在代码隐藏中完成的。但是你的消息来源在aspx上。因此,为了使其工作,您需要在插入之前在代码中绑定源数据

您还可以在
GetCareItems
方法中插入该项。那将是最简单的

YourList.Insert(5, new CareItemView() { Name = "--- Disabled ---" } );
YourList.Insert(5, new CareItemView() { Name = "--- Disabled ---" } );