Click here to Skip to main content
12,630,420 members (29,675 online)

how to change the color of the button through the databse

Ravimcts asked:

Open original thread
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];
       // string[] arr6 = 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();
           // arr6[d] = dr["status"].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] + "\n" + "status:- " + arr6[d];
            btnSubmit.Text = "Tabel_no :- " + arr3[d] + "\n" + "Chair_total:- " + arr5[d] ;
            btnSubmit.Width = 120;
            btnSubmit.Height = 120;
            // btnSubmit.Click += new System.EventHandler(btnSubmit_click);

 
            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.
Tags: ASP.NET, SQL-Server (SQL-server-2005)

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100