I have following c# code for a desktop application. It adds the controls dynamically to Panel1 by taking the values returned by the database function.
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 < 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]);
}
}
When I debugged it the values returned by the database function dops.get_lstMed() 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?