如何获取点击按钮的上一个/下一个索引?

时间:2016-06-03 06:45:56

标签: c# asp.net arrays

我想知道我点击的按钮的下一个按钮然后比较它是否点击了。如果我点击了索引a[5]的按钮,那么我必须比较是否点击了a[4]a[6]。如果先前选择了任一按钮,那么我只能选择a[5]。在此先感谢

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

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

0 个答案:

没有答案