比如这个DropDownList下拉选择控件,我忘里面添加了类别包括特殊符号,然后我下面判断的时候怎么判断下拉文本中的所有内容只要包涵有╋这个符号的我就要改变颜色,其实只要告诉我怎么判断是否包涵╋这个符号就可以了。 for (int i = 0; i < DropDownList1.Items.Count; i++)
{ if (DropDownList1.Items[i].Value == "╋")//这里我要逐行判断DropDownList里是否包含到╋这个符号,注意是包涵也就是可能会╋标题名这样的形式╋这个符号参杂其中。
{
DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");
} }
{ if (DropDownList1.Items[i].Value == "╋")//这里我要逐行判断DropDownList里是否包含到╋这个符号,注意是包涵也就是可能会╋标题名这样的形式╋这个符号参杂其中。
{
DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");
} }
string temp = "lskfj+-*/";
string isContained = "+";
int n = temp.indexof(isContained);
n>=0时,temp即包含isContained。
string isContained = "╋";
int n = temp.indexof(isContained);if(n > 0){
Respone.Write("包涵╋符号");
}
{
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
{ if (DropDownList1.Items[i].Value.indexof("╋") >= 0) {
DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");
}}
string isContained = "╋";
temp.Contains(isContained)
也可能是
if(DropDownList1.Items[i].Text.Contains("╋"))你两个都试下
string isContained = "╋";
int n = temp.IndexOf(isContained);
Response.Write("<script>alert('" + n + "');</script>");
//这里每行判断下来都是返回-1啊没任何变化·怎么可能还拿来判断呢···
哦了·,完美解决了·我刚取错参数了取得值我是要取文本内容去判断的
for (int i = 0; i < DropDownList1.Items.Count; i++)
{
if (DropDownList1.Items[i].ToString().Contains("╋"))
{
DropDownList1.Items[i].Attributes.Add("style ", "color: " + "Red");
} }
or
DropDownList1.Items[i].Value去判断