如何选择/取消选择动态创建的按钮

时间:2016-05-25 09:45:51

标签: c# asp.net

我有动态创建的按钮,例如1,2,3,4,5,6,7,8;如果我选择2,3,4,那么我就不能选择6并跳过4.或者你可以说,如果我选择2,3,4,5,6然后如果要取消选择4那么我必须取消选择首先是图5和图6。意味着如果我们选择了那么我们只能从最左侧或右侧取消选择

     private void GetControls()
          {
    count++;
    for (int i = 10; i < 12; i++)
    {
        for (int j = 0; j < 60; j += 15)
        {
            Button btn = new Button();
            btn.Text = i + "-" + j;
            btn.ID = i + "." + j;
            btn.Command += new CommandEventHandler(this.btn_Click);
           // btn.Click += btn_Click;
            flag = true;
            btn.CommandName = i + "-" + j;
            if (count==1)
            {
                PlaceHolder1.Controls.Add(btn);


            }
         }
   }   

}

private void btn_Click(object sender, CommandEventArgs e)
{
    count++;
    //ResetButton();
    Button btn = sender as Button;
    string ID = (sender as Button).ID;
    string text = (sender as Button).Text;

    Label1.Text = " Congrates! Your meeting time has been sheduled between "                                              + ID;


}  

                if (button.BackColor == Color.Yellow)
                {
                    button.BackColor = System.Drawing.Color.GhostWhite;
                }

                else if (button.BackColor == Color.GhostWhite)
                {
                    button.BackColor = System.Drawing.Color.GhostWhite;

                }
                else
                {

                    button.BackColor = System.Drawing.Color.Yellow;
                }

0 个答案:

没有答案