Hi
I have a form with 35 check boxes say .. i have a sqlserver DB with table contains status & id column ..
Status may be 0 or 1 or -1 .. id column (PK) is like 1 ,2 ,3 .. 35 values .
What i need is i want to make use of status values and assign the background-color to checkboxs ..
NOTE : CHECKBOX1 belongs to ID with 1 .. LIKE THAT checkBox2 belongs to ID 2 .. ... ... CHECKBOX35 USEs ID 35 & Its status value to asign Background color ..
Thank you
Have a nice day

VulpesPosted Jan 28, 2014, 6:47 AM
For a web app, it'll be something like this:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string connectionString = "blah";
string queryString = "SELECT id, status FROM someTable ORDER BY id";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int id = (int)reader["id"];
int status = (int)reader["status"];
CheckBox cb = (CheckBox)this.FindControl("CheckBox" + id);
switch(status)
{
case -1:
cb.BackColor = Color.Red;
break;
case 0:
cb.BackColor = Color.Green;
break;
case 1:
cb.BackColor = Color.Blue;
break;
}
}
reader.Close();
}
}
}
SUNIL GUTTAPosted Jan 28, 2014, 6:59 AM
Ty so so much :) god bless
SUNIL GUTTAPosted Jan 28, 2014, 6:12 AM
ANy ideas .... ..
Thank You Friend
VulpesPosted Jan 28, 2014, 6:00 AM
private void Form1_Load(object sender, EventArgs e)
{
string queryString = "SELECT id, status FROM someTable ORDER BY id";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int id = (int)reader["id"];
int status = (int)reader["status"];
CheckBox cb = (CheckBox)this.Controls["checkBox" + id];
switch(status)
{
case -1:
cb.BackColor = Color.Red;
break;
case 0:
cb.BackColor = Color.Green;
break;
case 1:
cb.BackColor = Color.Blue;
break;
}
}
reader.Close();
}
}