更新时间:2023-02-05 16:03:49
您可以使用Dropdownlist的Databound事件来更改项目的颜色。
尝试类似受保护 void DropDownList1_DataBound( object sender,EventArgs e)
{
foreach (ListItem item in DropDownList1.Items)
{
if ( string .Compare(item.Text, Telugu, true )== 0 ) // 更改条件
{
item.Attributes.Add( style, background-color:#110001); // 根据需要应用任何样式
item.Selected = false ; // 或根据您的需要启用虚假
}
}
}
希望这有帮助...
我通过javascript写如下来解决它...< script type = text / javascript >
函数setcolor(ddl){
for(i = 0; i < ddl.options.length; i ++) {
如果 (ddl.options [i] .value = = TELUGU) {
ddl.options [i] .style.color = 红色 ;
ddl.options [i] .disabled = disabled ;
}
}
}
< asp:dropdownlist id = dropmovie runat = server class = ddl onclick = setColor(this); style = width:210px;高度:30PX; background-color:#40E0D0 xmlns:asp = #unknown > < / asp:dropdownlist >
in this list i want to add red color to my string Telugu and make it as unselectable
thanks in advance
List<CascadingDropDownNameValue> list = new List<CascadingDropDownNameValue>();
string[] singlemoviedetails = null;
list.Add(new CascadingDropDownNameValue("TELUGU", "TELUGU"));
foreach (string single_moviedetails in total_moviedetails)
{
singlemoviedetails = single_moviedetails.Split('~');
if ("TELUGU".Equals(singlemoviedetails[2].ToString()))
{
list.Add(new CascadingDropDownNameValue(singlemoviedetails[1].ToString(), singlemoviedetails[0].ToString()));
}//if
}
You can use the Databound event of the Dropdownlist for changing the color of the item.
Try something likeprotected void DropDownList1_DataBound(object sender, EventArgs e) { foreach (ListItem item in DropDownList1.Items) { if (string.Compare(item.Text, "Telugu",true)==0)//change the condition { item.Attributes.Add("style", "background-color:#110001");//apply any style as your need item.Selected = false;// Or enabled false as per your need } } }
Hope this helps...
i solved it by writing in javascript as follows...<script type="text/javascript"> function setcolor(ddl) { for (i = 0; i < ddl.options.length; i++) { if (ddl.options[i].value == "TELUGU") { ddl.options[i].style.color = "red"; ddl.options[i].disabled = "disabled"; } } } <asp:dropdownlist id="dropmovie" runat="server" class="ddl" onclick="setColor(this);" style="width:210px; height:30px; background-color:#40E0D0" xmlns:asp="#unknown"></asp:dropdownlist>