rao kalyani

rao kalyani

  • NA
  • 1
  • 0

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

Jan 11 2009 6:33 PM
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)