2014-03-19 44 views
0

我有一个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"])); 
    } 

这很好地显示了这样的事情:

enter image description here

我知道弦没有颜色属性。 但是,我想知道是否有一种方法来获取以不同颜色显示dropDownList的内容?就像这样:

enter image description here

回答

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]); 
    }); 
}); 

http://jsfiddle.net/Db8bf/

有什么工作

相关问题