如何在CascadingDropDownNameValue中使一些列表项无法选择 [英] how can i make some list items unselectable in my CascadingDropDownNameValue

查看:120
本文介绍了如何在CascadingDropDownNameValue中使一些列表项无法选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此列表中我想为我的字符串Telugu添加红色并使其成为不可选择的

提前感谢



列表<   CascadingDropDownNameValue  >  list = new List <   CascadingDropDownNameValue  > ; (); 

string [] singlemoviedetails = null;

list.Add(new CascadingDropDownNameValue(TELUGU,TELUGU));


foreach(字符串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()));





} //如果
}

解决方案

您可以使用Dropdownlist的Databound事件来更改项目的颜色。



尝试类似

 受保护  void  DropDownList1_DataBound( object  sender,EventArgs e)
{
foreach (ListItem item in DropDownList1.Items)
{

if string .Compare(item.Text, < span class =code-string> Telugu, true )== 0 // 更改条件
{
item.Attributes.Add( style background-color:#110001); // 根据需要应用任何样式
item.Selected = false ; // 或根据您的需要启用虚假
}
}
}





希望这有帮助...


我通过javascript写如下来解决它...



 <   script    < span class =code-attribute> 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 = < span class =code-keyword> 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 like

protected 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>


这篇关于如何在CascadingDropDownNameValue中使一些列表项无法选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆