我定义了一个页面上有很多Button  aa, bb, cc, dd
然后有一个 string  strbt  类型的变量要求当string strbt 的值为 aa 时 button aa 的 BackColor为Red 
                        值为 bb 时 button bb 的 BackColor为Red 请问如何实现 ?  在线等  

解决方案 »

  1.   

    switch(strbt)
    {
     case "aa":
          aa.BackColor = Color.Red;
          break;
     case "bb":
          bb.BackColor = Color.Red;
          break;}
      

  2.   

    if(strbt == "aa"){
    aa.backcolor=color.red;
    bb.backcolor=defaultcolor;
    cc.backcolor=defaultcolor;
    dd.backcolor=defaultcolor;}
    else if(strbt == "bb"){
    bb.backcolor=color.red;
    aa.backcolor=defaultcolor;
    cc.backcolor=defaultcolor;
    dd.backcolor=defaultcolor;
    )
    ....
      

  3.   

    button数目太多 ,这样太麻烦了 , 能不能直接做类型的转换阿?
      

  4.   

    Button but=(Button)this.FindControl(strbt); if(but!=null)
    but.BackColor=Color.Red;
      

  5.   

    Control dad = aa.Parent;
    foreach(control c in dad)
    {
    if(c is Button)
    if ((Button)c.ID == strbt){
    (Button)c.Backcolor = color.red
    }
    else{
    (Button)c.Backcolor = defaultcolor;}
    }
    早说啊
      

  6.   

    string strbt = "你的值";
    switch(strbt)
    {
    case "aa":
    aa.BackColor=Color.Red;
    break;
    case "bb":
    bb.BackColor = Color.Red;
    break;}