我在Asp页面中有这个下拉列表:
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DropDownList1.Items.Add(string.Format("{0:}", ds.Tables[0].Rows[i]["Pnum"]) +
spacer + (ds.Tables[0].Rows[i]["Project"]) + spacer +
(ds.Tables[0].Rows[i]["Description"]));
}
很好地展示了这样的东西:
我知道字符串没有颜色属性。 但是,我想知道是否有办法让dropDownList的内容以不同的颜色显示?像这样:
答案 0 :(得分:0)
您可以使用微软描述的DefaultCellStyle Property,或者,您可以看到THIS帖子以获取更多帮助。
答案 1 :(得分:0)
使用简单的下拉列表,您无法拥有此行为。 您可以使用下拉列表自定义此
<div>
<input readonly type="text" style="color:red" id="t1">
<input readonly type="text" style="color:yellow" id="t2">
<select id="sel" style="float:right" >
<option id="p1,p2">p3</option>
<option id="p4,p5">p6</option>
<option id="p7,p8">p9</option>
</select>
</div>
CSS
input{
margin: 0px;
padding: 0px
border-width:0px;
border-color:white;
border-style: none;
}
div{
border-style: solid;
border-width: 1px;
border-color: black;
}
JS
$(document).ready(function(){
$("#sel").change(function(){
var ar = $("#sel option:selected").attr("id").split(",") ;
$("#t1").val(ar[0]);
$("#t2").val(ar[1]);
});
});
有一些工作要做