Click here to Skip to main content
15,885,879 members

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

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

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.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900