Monday, January 17, 2011

Run Time Created Button Color Change In C#

public void BtnColourChg()
{
DataAccess da = new DataAccess();
try
{
da.OpenConnection();
SqlDataReader dr = da.ExecuteReader("Select tableno from billtotal where status=1");
while (dr.Read())
{
foreach (Control item in this.Controls)
{
if (item is Button)
{
Button b = (Button)item;
if (b.Text == dr[0].ToString())
{
b.BackColor = System.Drawing.Color.Red;
}
}
}
}
}
catch (Exception ex) { }
finally { da.CloseConnection(); }
}

No comments:

Post a Comment