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

解决方案 »

  1.   

    通过if,或switch判断不行吗!!!
      

  2.   

    button 有 200个阿   有没有其他方法阿
      

  3.   

    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;}
    }
      

  4.   

    还有一个: Button but=(Button)this.FindControl(strbt); if(but!=null)
    but.BackColor=Color.Red;
      

  5.   

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