How do I change the color of a row in a datagrid by value of a cel

G

Guest

Ok people, here is what I am trying to do.

I have a SqlDataReader that populates data into a DataGrid on a website.

I want to be able to make every row in the DataGrid "Red" where the cell
"Reason_Code" in that row != 0 . Reason_Code is a type INT

Below is the code I am using, anyone got any ideas.

private void Page_Load(object sender, System.EventArgs e)
{

SqlConnection nike01 = new SqlConnection();
nike01.ConnectionString =
"Server=nike-svr-01;Database=IASLogs;Trusted_Connection=True;";

SqlCommand ias_query = new SqlCommand();
ias_query.CommandText = "SELECT A1.timestamp as [Date], " +
"A1.F_Q_User_Name as [User], A1.NAS_Identifier as [Access Point], "+
"A1.Calling_Station_Id as [Calling Station], R1.Reason_Code,
R1.Reason_text "+
"FROM accounting_data A1, accounting_data A2, r_codes R1 "+
"WHERE A1.Class = A2.Class "+
"AND A1.Reason_Code = R1.reason_code ORDER BY A1.timestamp DESC";
ias_query.Connection = nike01;

nike01.Open();

DataGrid1.DataSource = ias_query.ExecuteReader();
DataGrid1.DataBind();



nike01.Close();

}
 
C

Chris Botha

DataGrid1.DataBind()
Dim oneItem As DataGridItem
For Each oneItem In DataGrid1.Items
If oneItem.Cells(3).Text <> "0" Then
oneItem.Cells(3).BackColor = Drawing.Color.Red
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top