本文介绍了关于if语句和数组C#.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的html

My html

<tr <%# FormatColorRow(DataBinder.Eval(Container.DataItem,"bugstoreid").ToString()) %>  id=''A1''     ><tr<%#>


我想突出显示包含bugstoreid的行,该行可能是多个
称我的功能为


I want to highlight rows containing bugstoreid which could be multiple
called my function as

protected string FormatColorRow(string bugstoreid)
    {
       string[] names = new string[] { "170", "171"};
       //*my problem goes here.

       if (bugstoreid == names[0].ToString() || bugstoreid == names[1].ToString())
       {
          return "style=''backGround-color:LightBlue''";
       }

       return "style=''backgroundColor=''''''";
    }



名称尽可能多,可以是{"170","171",..",......}
我不知道如何在此处声明if语句以一次返回所有名称的样式



Names are as multiple as possible can be {"170","171",......."",...........}
I don''t know how to declare if statement here to return style with all names at once

string names=new string{"170,"171",....}

以逗号分隔的表实体的值...请帮助我.
提前谢谢!

[edit]添加了代码块,禁用了忽略HTML ..."选项,整洁-OriginalGriff [/edit]

value of table entity seperated by comma ...please help me.
Thanks in advance!

[edit]Code block added, "Ignore HTML..." option disabled, general tidy - OriginalGriff[/edit]

推荐答案

protected string FormatColorRow(string bugstoreid)
    {
       List<string> names = new List<string> { "170", "171"};
       //*my problem goes here.
       if (names.Contains(bugstoreid))
       {
          return "style='backGround-color:LightBlue'";
       }
       return "style='backgroundColor='''";
    }
</string></string>



希望它会帮助您.



Hope it hepls.


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string bugstoreid = GridView1.DataKeys[0].Value.ToString();
            string[] names = new string[] { "170", "171" };
            if (bugstoreid == names[0].ToString() || bugstoreid == names[1].ToString())
            {
                e.Row.BackColor = "LightBlue";
            }
        }
    }



谢谢,
Imdadhusen



Thanks,
Imdadhusen


if (bugstoreid == names[0].ToString() || bugstoreid == names[1].ToString())
   {
   return "style='backGround-color:LightBlue'";
   }  

with

with

foreach (string name in names)
   {
   if (bugstoreid == name)
      {
      return "style='backGround-color:LightBlue'";
      }
   }

BTW:您不需要在字符串上使用ToString:它已经是一个...

BTW: you do not need to use ToString on a string: it is one already...


这篇关于关于if语句和数组C#.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 16:16