protected void Page_Load(object sender, EventArgs e)
{
{
string aa = "";
SqlConnection con = new SqlConnection(connStr);
SqlCommand sd = new SqlCommand("select max(v) as a from seats", con);
con.Open();
SqlDataReader drr = sd.ExecuteReader();
if (drr.Read())
{
aa = drr["a"].ToString();
}
con.Close();
int d = 0;
int f = 0;
f = Convert.ToInt16(aa);
Label1.Text = f.ToString();
string[] arr3 = new string[f];
string[] arr5 = new string[f];
SqlCommand cmd = new SqlCommand("select Table_No,Chair_total,status,v from seats", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
arr3[d] = dr["Table_No"].ToString();
arr5[d] = dr["Chair_total"].ToString();
d++;
}
con.Close();
d = 0;
for (int i = 1; i <= f; i++)
{
Button btnSubmit = new Button();
btnSubmit.ID = i.ToString();
btnSubmit.Text = "Tabel_no :- " + arr3[d] + "\n" + "Chair_total:- " + arr5[d] ;
btnSubmit.Width = 120;
btnSubmit.Height = 120;
d++;
Panel1.Controls.Add(btnSubmit);
Response.Write("\n");
string c;
SqlCommand cmd2 = new SqlCommand("select image from seats where Table_No='" + Tabel_no.Text + "' and Chair_total='" + Chait_total.Text + "' and status='" + status.Text + "' ", con);
con.Open();
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
c = dr2[0].ToString();
if (c == "red")
btnSubmit.BackColor = System.Drawing.Color.Red;
else if (c == "yellow")
btnSubmit.BackColor = System.Drawing.Color.Yellow;
else
btnSubmit.BackColor = System.Drawing.Color.Green;
c = "";
}
con.Close();
}
}
}
i am creating the button dynamical using the database, my buttons are created but iam also trying to change the color of button using the value in database, and also trying to fetch some details from database to my button . but iam failed to do this, so plz check where iam wrong.
1- i want change the color of button using the database value.
2- want to print the details over the button text using the database value.