473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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();

}
Nov 19 '05 #1
1 1317


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
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
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();

}

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
2
by: Tor Inge Rislaa | last post by:
How to change row height in a DataGrid I have DataGrid that is filled with data from a table in a DataSet. The content of the cells is text of more than one line (as a note field). What I...
4
by: Rob Kroese | last post by:
I've got a form with a datagrid that displays a list of items, along with several textboxes, comboboxes, etc., that display the details for the selected item. The columns in the datagrid and the...
5
by: HS1 | last post by:
Hello I have a datagrid to show data for a database table using "seclect * from tablename" The datagrid works OK. However, I want to change the name of the fields in the database to other...
6
by: timbobd | last post by:
I have a Windows form that displays a database table in a DataGrid. When you click on a row, the row's values get copied to bound TextBoxes below, and when the "Save" button is clicked the database...
2
by: simon | last post by:
hello, new to vb.net, have a few questions about DataGrid. I have a dataGrid that is working pulling a dataset back from a stored proc and binding to the datagrid for display the datagrid's...
2
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Greetings, I am trying to find out how to do something that on the surface seems like it should be very simple to do. I have a datagrid with a datatable bound to it using the SetDataBinding...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.