1
Answer

Error:Make sure that maximum index on a list is less than the list size

rao kalyani

rao kalyani

15y
9.2k
1
Hi ,


 I created a methode to Add buttons and I called in Page_Load().But I wan to display which i button clicked on a Label

This is code...
public void AddButton(Button b1)
    {
         string s;
         Panel p = new Panel();
         Button[] b = new Button[10];
        for (int i = 0; i < b.Length; i++)
        {
            s = i.ToString();
            b[i] = new Button();
            b[i].Text = Convert.ToString(i);
            p.Controls.Add(b[i]);
            b[i].Click += new EventHandler(Btn1_Click);
          
        }
     }
Its adding buttons to Panel.

Button Click
public void Btn1_Click(object obj, EventArgs ergs)
    {
      
        Label1.Text = b[i].Text;  

    }
    
When I am running this application I am getting Error
Make sure that maximum index on a list is less than the list size.

Please tell me where I am doing wrong

Thanks

Kalyani
Answers (1)