I am making a application in asp.net which shows the values in gridview from the database.In database i am having a colmn named as StatusId which has a value of 1 or 2 or 3.
I tried to show the grid view rows in different color by their statusId values. But it never works. How can i do it in asp.net.
Here is my code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Connection.Open();
SqlCommand Command1 = Connection.CreateCommand();
Command1.CommandText = "Select statusColor from status where statusId=(Select statusId from fileInfo where userId=(Select userId from userInfo where email='" + Session["email"].ToString() + "'))";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
using (SqlDataReader reader = Command1.ExecuteReader())
{
while (reader.Read())
{
statusId = reader["statusColor"].ToString();
}
GridView1.RowStyle.BackColor = Color.FromName(statusId);
}
}
foreach (GridViewRow row in GridView1.Rows)
{
row.BackColor = Color.Green;
}
SqlCommand com = new SqlCommand("gridcolor", Connection);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@statusId", statusId);
com.Parameters.Add("@statusColor", SqlDbType.NVarChar, 30);
com.Parameters["@statusColor"].Direction = ParameterDirection.Output;
com.ExecuteNonQuery();
string msg = (string)com.Parameters["@statusColor"].Value;
Connection.Close();
}
What is the mistake i am doing here?
EDIT
I have the color codes which are stored in the database named as statusColor. I have to apply those color to these status.