"DH" <sa****@gamesboutique.co.zawrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"web develepor here trying to get to grips with winforms"
I have a list of departments for a restaurant menu i.e Booz, Burgers etc
and want to display a vertical list of buttons (depts pulled from db).
This would be done with a repeater control in asp.net
There might be a solution that uses databinding, but I would do it in
code, creating the buttons in a loop:
SqlCommand cmd = new SqlCommand("Select * from depts", connection);
connection.Open();
SqlDataReader rdr = cmd.ExecuteReader();
int i=0;
while (rdr.Read())
{
string buttonName = rdr("Name").ToString();
Button b = new Button();
b.Text = buttonName;
b.Top = (i++)*(b.Height+5);
b.Left = 5;
Panel1.Controls.Add(b);
b.Click += new EventHandler(MyButtons_Click);
}
rdr.Close();
connection.Close();