2016-06-09 37 views
1

我在C#控制器中创建了一个下拉列表,并使用@ Html.DropDownListFor来显示它。将selectedListItem的颜色更改为C#中的红色

问题是我想以红色显示选定的值。它发生在用户去修改页面来改变他/她的选择并下拉时,然后应该显示他以前用红色选择的内容。

我已经创建了下拉菜单,现在用户可以看到以前选择的值。我只是不知道如何改变颜色在C#代码,而我这样做

if (financierEntity.EntityId == selectedFinancierEntityId) 
{ 
    SelectListItem sli = new SelectListItem 
    { 
     Text = financierEntity.NodeName, 
     Value = financierEntity.EntityId.ToString(), 
     Selected = true, 
     // need to change the text in red color ? 
    }; 

} 

这是我考虑

@Html.DropDownListFor(model => model.SelectedFinancier, Model.FinancierEntities) 
+0

你需要这样做使用CSS – gldraphael

+0

谢谢,但你可以请详细解释如何? – Adeel

+0

如果选择的项目被更改,哪个项目应该是红色的?先前选择的项目还是新项目? – gldraphael

回答

1

我没有尝试过的代码,代码的事,但对这些行应该工作:

<select name="SelectedFinancier"> 
    @foreach (var item in Model.FinancierEntities) 
    { 
     <option value="@item.Value" 
      @(item.Selected ? "selected" : "") 
      style="color: red">@item.Text</option> 
    } 
</select> 
+0

谢谢你。我为我工作,但我需要改变一点 – Adeel

相关问题