473,385 Members | 1,912 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.

Set Background Color Using Column Value?

TF
Very newbie question and I hope this is the right group. I have a
table on a web page which contains info about paint colors. One column
contains the hex value for the color's RGB value. I want to display
info from the table in a grid or table and use the column value from
the RGBHex column to set each row's back ground color. I can just
about do this in my sleep in old style ASP using <%%tags but I would
like to implement it in .NET 2. My website has this implemented in
old ASP here: www.paintmatcher.com/tool/tool.asp Any help is greatly
appreciated.

Mar 17 '07 #1
10 9788
On Mar 17, 1:26 pm, "TF" <TJForw...@gmail.comwrote:
the RGBHex column to set each row's back ground color. I can just
about do this in my sleep in old style ASP using <%%tags
it could be the same as in ASP 3:

bgcolor="#<%=hex_value%>"

where "hex_value" is a variable
Mar 17 '07 #2
TF
Here's a snippet of the code created by MS Vis Web Developer 05
Express. The data from the table displays just fine. I want to set
the back color of each row based on the value of the "RGBHex" field.

<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to
display.">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Brand" HeaderText="Brand"
SortExpression="Brand" />
<asp:BoundField DataField="Colorname"
HeaderText="Colorname" SortExpression="Colorname" />
<asp:BoundField DataField="RGBValue" HeaderText="RGBValue"
SortExpression="RGBValue" />
<asp:BoundField DataField="RGBHex" HeaderText="RGBHex"
SortExpression="RGBHex" />
</Columns>
</asp:GridView>

Could I use ASP 3 <%%tags inside the BoundField tag? How would I
call the field value using ASP.NET to assign to the variable? Or
maybe there's a better solution than using a GridView. Any other
ideas?

Thanks.
Alexey Smirnov wrote:
On Mar 17, 1:26 pm, "TF" <TJForw...@gmail.comwrote:
the RGBHex column to set each row's back ground color. I can just
about do this in my sleep in old style ASP using <%%tags

it could be the same as in ASP 3:

bgcolor="#<%=hex_value%>"

where "hex_value" is a variable
Mar 17 '07 #3

More see here!

http://www.flash50.com/index.php
Mar 18 '07 #4
On Mar 17, 10:26 pm, "TF" <TJForw...@gmail.comwrote:
Here's a snippet of the code created by MS Vis Web Developer 05
Express. The data from the table displays just fine. I want to set
the back color of each row based on the value of the "RGBHex" field.

<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to
display.">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Brand" HeaderText="Brand"
SortExpression="Brand" />
<asp:BoundField DataField="Colorname"
HeaderText="Colorname" SortExpression="Colorname" />
<asp:BoundField DataField="RGBValue" HeaderText="RGBValue"
SortExpression="RGBValue" />
<asp:BoundField DataField="RGBHex" HeaderText="RGBHex"
SortExpression="RGBHex" />
</Columns>
</asp:GridView>

Could I use ASP 3 <%%tags inside the BoundField tag? How would I
call the field value using ASP.NET to assign to the variable? Or
maybe there's a better solution than using a GridView. Any other
ideas?
In this case you should rewrite a GridView_RowDataBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound="GridView1_RowDataBound"....

and add the GridView1_RowDataBound event to your code (code-behind)

C#:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"]; // e.g. "#000000"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);
}

}

I didn't test it but it should work, I think

Mar 18 '07 #5
TF
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Mar 17, 10:26 pm, "TF" <TJForw...@gmail.comwrote:
Here's a snippet of the code created by MS Vis Web Developer 05
Express. The data from the table displays just fine. I want to set
the back color of each row based on the value of the "RGBHex" field.
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to
display.">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Brand" HeaderText="Brand"
SortExpression="Brand" />
<asp:BoundField DataField="Colorname"
HeaderText="Colorname" SortExpression="Colorname" />
<asp:BoundField DataField="RGBValue" HeaderText="RGBValue"
SortExpression="RGBValue" />
<asp:BoundField DataField="RGBHex" HeaderText="RGBHex"
SortExpression="RGBHex" />
</Columns>
</asp:GridView>
Could I use ASP 3 <%%tags inside the BoundField tag? How would I
call the field value using ASP.NET to assign to the variable? Or
maybe there's a better solution than using a GridView. Any other
ideas?

In this case you should rewrite a GridView_RowDataBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound="GridView1_RowDataBound"....

and add the GridView1_RowDataBound event to your code (code-behind)

C#:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"]; // e.g. "#000000"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);

}
}

I didn't test it but it should work, I think
OK. Where do I put that C# code snippet?

Mar 18 '07 #6
TF
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Mar 17, 10:26 pm, "TF" <TJForw...@gmail.comwrote:
Here's a snippet of the code created by MS Vis Web Developer 05
Express. The data from the table displays just fine. I want to set
the back color of each row based on the value of the "RGBHex" field.
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to
display.">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Brand" HeaderText="Brand"
SortExpression="Brand" />
<asp:BoundField DataField="Colorname"
HeaderText="Colorname" SortExpression="Colorname" />
<asp:BoundField DataField="RGBValue" HeaderText="RGBValue"
SortExpression="RGBValue" />
<asp:BoundField DataField="RGBHex" HeaderText="RGBHex"
SortExpression="RGBHex" />
</Columns>
</asp:GridView>
Could I use ASP 3 <%%tags inside the BoundField tag? How would I
call the field value using ASP.NET to assign to the variable? Or
maybe there's a better solution than using a GridView. Any other
ideas?

In this case you should rewrite a GridView_RowDataBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound="GridView1_RowDataBound"....

and add the GridView1_RowDataBound event to your code (code-behind)

C#:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"]; // e.g. "#000000"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);

}
}

I didn't test it but it should work, I think
OK. Where do I put that C# code snippet?

Mar 18 '07 #7
TF
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Mar 17, 10:26 pm, "TF" <TJForw...@gmail.comwrote:
Here's a snippet of the code created by MS Vis Web Developer 05
Express. The data from the table displays just fine. I want to set
the back color of each row based on the value of the "RGBHex" field.
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to
display.">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Brand" HeaderText="Brand"
SortExpression="Brand" />
<asp:BoundField DataField="Colorname"
HeaderText="Colorname" SortExpression="Colorname" />
<asp:BoundField DataField="RGBValue" HeaderText="RGBValue"
SortExpression="RGBValue" />
<asp:BoundField DataField="RGBHex" HeaderText="RGBHex"
SortExpression="RGBHex" />
</Columns>
</asp:GridView>
Could I use ASP 3 <%%tags inside the BoundField tag? How would I
call the field value using ASP.NET to assign to the variable? Or
maybe there's a better solution than using a GridView. Any other
ideas?

In this case you should rewrite a GridView_RowDataBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound="GridView1_RowDataBound"....

and add the GridView1_RowDataBound event to your code (code-behind)

C#:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"]; // e.g. "#000000"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);

}
}

I didn't test it but it should work, I think
OK. Where do I put that C# code snippet?

Mar 18 '07 #8
TF
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Mar 17, 10:26 pm, "TF" <TJForw...@gmail.comwrote:
Here's a snippet of the code created by MS Vis Web Developer 05
Express. The data from the table displays just fine. I want to set
the back color of each row based on the value of the "RGBHex" field.
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to
display.">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Brand" HeaderText="Brand"
SortExpression="Brand" />
<asp:BoundField DataField="Colorname"
HeaderText="Colorname" SortExpression="Colorname" />
<asp:BoundField DataField="RGBValue" HeaderText="RGBValue"
SortExpression="RGBValue" />
<asp:BoundField DataField="RGBHex" HeaderText="RGBHex"
SortExpression="RGBHex" />
</Columns>
</asp:GridView>
Could I use ASP 3 <%%tags inside the BoundField tag? How would I
call the field value using ASP.NET to assign to the variable? Or
maybe there's a better solution than using a GridView. Any other
ideas?

In this case you should rewrite a GridView_RowDataBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound="GridView1_RowDataBound"....

and add the GridView1_RowDataBound event to your code (code-behind)

C#:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"]; // e.g. "#000000"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);

}
}

I didn't test it but it should work, I think
OK. I may be getting this now. I made this the first line of my
default.aspx.

<%@ Page Language="C#" AutoEventWireup="false"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
And this is the contents of the default.aspx.cs file. Renamed my grid
GridView2 by the way.
protected void GridView2_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"];
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);
}
}

Getting these compilation errors.

c:\...Default.aspx.cs(1,11): error CS1518: Expected class, delegate,
enum, interface, or struct
c:\...Default.aspx.cs(6,27): error CS1001: Identifier expected
c:\...Default.aspx.cs(9,1): error CS1022: Type or namespace
definition, or end-of-file expected

I feel like I'm getting close but I just can't get it. Thank you for
your help.

TF
Mar 18 '07 #9
On Mar 18, 9:24 pm, "TF" <TJForw...@gmail.comwrote:
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:


On Mar 17, 10:26 pm, "TF" <TJForw...@gmail.comwrote:
Here's a snippet of the code created by MS Vis Web Developer 05
Express. The data from the table displays just fine. I want to set
the back color of each row based on the value of the "RGBHex" field.
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to
display.">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Brand" HeaderText="Brand"
SortExpression="Brand" />
<asp:BoundField DataField="Colorname"
HeaderText="Colorname" SortExpression="Colorname" />
<asp:BoundField DataField="RGBValue" HeaderText="RGBValue"
SortExpression="RGBValue" />
<asp:BoundField DataField="RGBHex" HeaderText="RGBHex"
SortExpression="RGBHex" />
</Columns>
</asp:GridView>
Could I use ASP 3 <%%tags inside the BoundField tag? How would I
call the field value using ASP.NET to assign to the variable? Or
maybe there's a better solution than using a GridView. Any other
ideas?
In this case you should rewrite a GridView_RowDataBound event.
Change <asp:GridView ID="GridView1"
OnRowDataBound="GridView1_RowDataBound"....
and add the GridView1_RowDataBound event to your code (code-behind)
C#:
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"]; // e.g. "#000000"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);
}
}
I didn't test it but it should work, I think

OK. I may be getting this now. I made this the first line of my
default.aspx.

<%@ Page Language="C#" AutoEventWireup="false"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

And this is the contents of the default.aspx.cs file. Renamed my grid
GridView2 by the way.

protected void GridView2_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"];
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);

}
}

Getting these compilation errors.

c:\...Default.aspx.cs(1,11): error CS1518: Expected class, delegate,
enum, interface, or struct
c:\...Default.aspx.cs(6,27): error CS1001: Identifier expected
c:\...Default.aspx.cs(9,1): error CS1022: Type or namespace
definition, or end-of-file expected

I feel like I'm getting close but I just can't get it. Thank you for
your help.

TF- Hide quoted text -

- Show quoted text -
Mate, you have to start from the basic.

It told you that you miss a class, that is you have to define the
_Default

Remember, you said <%@ Page .... Inherits="_Default"
<!--------------- This is the name of your class

So, the code-behind should be like this:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

...................code here...................

}

Mar 19 '07 #10
TF
On Mar 17, 7:26 am, "TF" <TJForw...@gmail.comwrote:
Very newbie question and I hope this is the right group. I have a
table on a web page which contains info about paint colors. One column
contains the hex value for the color's RGB value. I want to display
info from the table in a grid or table and use the column value from
the RGBHex column to set each row's back ground color. I can just
about do this in my sleep in old style ASP using <%%tags but I would
like to implement it in .NET 2. My website has this implemented in
old ASP here: www.paintmatcher.com/tool/tool.asp Any help is greatly
appreciated.
Got it to work now. Thank you all very much!

Mar 20 '07 #11

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

Similar topics

19
by: Jerry | last post by:
Hi Folks, Ok, here's my story. I was asked to create a website for the church I attend. I am a complete newbie to creating websites. So, I did the usual -- did a bunch of googling, found...
11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
1
by: RJ | last post by:
Hello! I am trying to lay out a left navigation column with a background image, where the left nav column runs the entire scrolled height/length of the page. The float:left column layout works...
7
by: PJ | last post by:
How can you set the background color of individual columns in a datagrid to be different to others? The table styles only allow you to do this at the grid level for all columns.
4
by: John Smith | last post by:
Hi All; I am using the HeaderAndDataAlignColumn class from Ken Tucker. I have customized it for a wider row. I reposition the DrawString method so the text is centered vertically in the row. ...
0
by: JC Voon | last post by:
Hi All: I'm new in Threading and Web Services, can someone please verify my code, i'm not sure whether this is the correct way, althought it is partially work, but some time it will raise...
11
by: free4trample | last post by:
First of all let me say that I know very little about javascript. what i need to do is to write a javascript functin which will change the background color of the table rows based on entrees in...
1
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm populating a datagridview from a data table. I would like to set the back ground color of each row based on a column value in that row. If the value of a column for a particular row is set...
2
by: bsrcss | last post by:
I added a 3 column lists to my site using the techniques shown on http://www.communitymx.com/content/article.cfm?page=1&cid=27F87 I first tried their code by itself and it worked fine. When I...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.