databinding buttons verticaly

  • Thread starter Thread starter DH
  • Start date Start date
D

DH

"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

Regards

ER
 
DH said:
"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();
 
Back
Top