比如这个DropDownList下拉选择控件,我忘里面添加了类别包括特殊符号,然后我下面判断的时候怎么判断下拉文本中的所有内容只要包涵有╋这个符号的我就要改变颜色,其实只要告诉我怎么判断是否包涵╋这个符号就可以了。                for (int i = 0; i < DropDownList1.Items.Count; i++)
                {                    if (DropDownList1.Items[i].Value == "╋")//这里我要逐行判断DropDownList里是否包含到╋这个符号,注意是包涵也就是可能会╋标题名这样的形式╋这个符号参杂其中。
                    {
                        DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");
                    }                }

解决方案 »

  1.   


    string temp = "lskfj+-*/";
    string isContained = "+";
    int n = temp.indexof(isContained);
    n>=0时,temp即包含isContained。
      

  2.   

    是否是这样?string temp = "lskfj+-*╋/";
    string isContained = "╋";
    int n = temp.indexof(isContained);if(n > 0){
    Respone.Write("包涵╋符号");
    }
      

  3.   

    或者用Containsusing System;class Sample 
    {
        public static void Main() 
        {
        string s1 = "The quick brown fox jumps over the lazy dog";
        string s2 = "fox";
        bool b;
        b = s1.Contains(s2);
        Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
        }
    }代码来自msdn:
    http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx
      

  4.   

    for (int i = 0; i < DropDownList1.Items.Count; i++)
    {  if (DropDownList1.Items[i].Value.indexof("╋") >= 0)  {
      DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");
      }}
      

  5.   

    string temp = "lskfj+-*╋/";
    string isContained = "╋";
    temp.Contains(isContained) 
      

  6.   

    DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");改变不了 DropDownList里面项的颜色只能用div模拟
      

  7.   

    if(DropDownList1.Items[i].Value.Contains("╋"))
    也可能是
    if(DropDownList1.Items[i].Text.Contains("╋"))你两个都试下
      

  8.   

                string temp = DropDownList1.Items[i].Value;
                string isContained = "╋";
                int n = temp.IndexOf(isContained);
                Response.Write("<script>alert('" + n + "');</script>");
    //这里每行判断下来都是返回-1啊没任何变化·怎么可能还拿来判断呢···
      

  9.   

    C# 版块,你是 winform 程序把~我当是 webform 呢  winform 中是可以的
      

  10.   

    嗯,也是可以的.我一直在想 option 鼠标悬停变色那个是需要模拟的.你分别设置 option 的背景色是没问题的
      

  11.   


    哦了·,完美解决了·我刚取错参数了取得值我是要取文本内容去判断的
                for (int i = 0; i < DropDownList1.Items.Count; i++)
                {
                    if (DropDownList1.Items[i].ToString().Contains("╋"))
                    {
                        DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");
                    }                          }
      

  12.   

     if (DropDownList1.Items[i].ToString().Contains("╋"))你的 DropDownList1 怎么绑定的应该用DropDownList1.Items[i].Text
    or
    DropDownList1.Items[i].Value去判断
      

  13.   

    嗯嗯··我刚眼花了·没注意这个·刚用Value去判断了·现在好了· ·