title: Unable to add user controls to a panel dynamically
body: <p>I have following c# code for a desktop application. It adds the controls dynamically to <code>Panel1</code> by taking the values returned by the database function.</p>
  
  <pre><code>private void loadData()
          {
              string[] names = dops.get_lstMed(textBox2.Text); //fetching values from database
              MediRow[] mr = new MediRow[names.Length]; //User control array
              panel1.Controls.Clear();
              for (int i = 0; i &lt; names.Length; i++)
              {
                  mr[i] = new MediRow();
                  mr[i].MedName = names[i];
                  mr[i].AvailQty = dops.get_Med_qty(names[i]).ToString();
                  mr[i].Quantity = "0";
                  panel1.Controls.Add(mr[i]);
              }
  
          }
  </code></pre>
  
  <p>When I debugged it the values returned by the database function <code>dops.get_lstMed()</code> are correct and even the loop is working as it should be. But the problem is that only one control is added in the panel even database has more than one rows. Please tell me whats wrong with the code?</p>