473,748 Members | 9,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9813
On Mar 17, 1:26 pm, "TF" <TJForw...@gmai l.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="#<%=he x_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="T rue"
AutoGenerateCol umns="False"
DataKeyNames="I D" DataSourceID="A ccessDataSource 2"
EmptyDataText=" There are no data records to
display.">
<Columns>
<asp:BoundFie ld DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="Bran d" HeaderText="Bra nd"
SortExpression= "Brand" />
<asp:BoundFie ld DataField="Colo rname"
HeaderText="Col orname" SortExpression= "Colorname" />
<asp:BoundFie ld DataField="RGBV alue" HeaderText="RGB Value"
SortExpression= "RGBValue" />
<asp:BoundFie ld DataField="RGBH ex" HeaderText="RGB Hex"
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...@gmai l.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="#<%=he x_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...@gmai l.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="T rue"
AutoGenerateCol umns="False"
DataKeyNames="I D" DataSourceID="A ccessDataSource 2"
EmptyDataText=" There are no data records to
display.">
<Columns>
<asp:BoundFie ld DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="Bran d" HeaderText="Bra nd"
SortExpression= "Brand" />
<asp:BoundFie ld DataField="Colo rname"
HeaderText="Col orname" SortExpression= "Colorname" />
<asp:BoundFie ld DataField="RGBV alue" HeaderText="RGB Value"
SortExpression= "RGBValue" />
<asp:BoundFie ld DataField="RGBH ex" HeaderText="RGB Hex"
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_RowDat aBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound= "GridView1_RowD ataBound"....

and add the GridView1_RowDa taBound event to your code (code-behind)

C#:

protected void GridView1_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{

if (e.Row.RowType == DataControlRowT ype.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...@gmai l.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="T rue"
AutoGenerateCol umns="False"
DataKeyNames="I D" DataSourceID="A ccessDataSource 2"
EmptyDataText=" There are no data records to
display.">
<Columns>
<asp:BoundFie ld DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="Bran d" HeaderText="Bra nd"
SortExpression= "Brand" />
<asp:BoundFie ld DataField="Colo rname"
HeaderText="Col orname" SortExpression= "Colorname" />
<asp:BoundFie ld DataField="RGBV alue" HeaderText="RGB Value"
SortExpression= "RGBValue" />
<asp:BoundFie ld DataField="RGBH ex" HeaderText="RGB Hex"
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_RowDat aBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound= "GridView1_RowD ataBound"....

and add the GridView1_RowDa taBound event to your code (code-behind)

C#:

protected void GridView1_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{

if (e.Row.RowType == DataControlRowT ype.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...@gmai l.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="T rue"
AutoGenerateCol umns="False"
DataKeyNames="I D" DataSourceID="A ccessDataSource 2"
EmptyDataText=" There are no data records to
display.">
<Columns>
<asp:BoundFie ld DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="Bran d" HeaderText="Bra nd"
SortExpression= "Brand" />
<asp:BoundFie ld DataField="Colo rname"
HeaderText="Col orname" SortExpression= "Colorname" />
<asp:BoundFie ld DataField="RGBV alue" HeaderText="RGB Value"
SortExpression= "RGBValue" />
<asp:BoundFie ld DataField="RGBH ex" HeaderText="RGB Hex"
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_RowDat aBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound= "GridView1_RowD ataBound"....

and add the GridView1_RowDa taBound event to your code (code-behind)

C#:

protected void GridView1_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{

if (e.Row.RowType == DataControlRowT ype.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...@gmai l.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="T rue"
AutoGenerateCol umns="False"
DataKeyNames="I D" DataSourceID="A ccessDataSource 2"
EmptyDataText=" There are no data records to
display.">
<Columns>
<asp:BoundFie ld DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="Bran d" HeaderText="Bra nd"
SortExpression= "Brand" />
<asp:BoundFie ld DataField="Colo rname"
HeaderText="Col orname" SortExpression= "Colorname" />
<asp:BoundFie ld DataField="RGBV alue" HeaderText="RGB Value"
SortExpression= "RGBValue" />
<asp:BoundFie ld DataField="RGBH ex" HeaderText="RGB Hex"
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_RowDat aBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound= "GridView1_RowD ataBound"....

and add the GridView1_RowDa taBound event to your code (code-behind)

C#:

protected void GridView1_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{

if (e.Row.RowType == DataControlRowT ype.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...@gmai l.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="T rue"
AutoGenerateCol umns="False"
DataKeyNames="I D" DataSourceID="A ccessDataSource 2"
EmptyDataText=" There are no data records to
display.">
<Columns>
<asp:BoundFie ld DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="Bran d" HeaderText="Bra nd"
SortExpression= "Brand" />
<asp:BoundFie ld DataField="Colo rname"
HeaderText="Col orname" SortExpression= "Colorname" />
<asp:BoundFie ld DataField="RGBV alue" HeaderText="RGB Value"
SortExpression= "RGBValue" />
<asp:BoundFie ld DataField="RGBH ex" HeaderText="RGB Hex"
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_RowDat aBound event.

Change <asp:GridView ID="GridView1"
OnRowDataBound= "GridView1_RowD ataBound"....

and add the GridView1_RowDa taBound event to your code (code-behind)

C#:

protected void GridView1_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{

if (e.Row.RowType == DataControlRowT ype.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="Defau lt.aspx.cs" Inherits="_Defa ult" %>
And this is the contents of the default.aspx.cs file. Renamed my grid
GridView2 by the way.
protected void GridView2_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
string c = e.Row.DataItem["RGBHex"];
e.Row.BackColor = System.Drawing. ColorTranslator .FromHtml(c);
}
}

Getting these compilation errors.

c:\...Default.a spx.cs(1,11): error CS1518: Expected class, delegate,
enum, interface, or struct
c:\...Default.a spx.cs(6,27): error CS1001: Identifier expected
c:\...Default.a spx.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...@gmai l.comwrote:
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :


On Mar 17, 10:26 pm, "TF" <TJForw...@gmai l.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="T rue"
AutoGenerateCol umns="False"
DataKeyNames="I D" DataSourceID="A ccessDataSource 2"
EmptyDataText=" There are no data records to
display.">
<Columns>
<asp:BoundFie ld DataField="ID" HeaderText="ID"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="Bran d" HeaderText="Bra nd"
SortExpression= "Brand" />
<asp:BoundFie ld DataField="Colo rname"
HeaderText="Col orname" SortExpression= "Colorname" />
<asp:BoundFie ld DataField="RGBV alue" HeaderText="RGB Value"
SortExpression= "RGBValue" />
<asp:BoundFie ld DataField="RGBH ex" HeaderText="RGB Hex"
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_RowDat aBound event.
Change <asp:GridView ID="GridView1"
OnRowDataBound= "GridView1_RowD ataBound"....
and add the GridView1_RowDa taBound event to your code (code-behind)
C#:
protected void GridView1_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.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="Defau lt.aspx.cs" Inherits="_Defa ult" %>

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

protected void GridView2_RowDa taBound(object sender,
GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
string c = e.Row.DataItem["RGBHex"];
e.Row.BackColor = System.Drawing. ColorTranslator .FromHtml(c);

}
}

Getting these compilation errors.

c:\...Default.a spx.cs(1,11): error CS1518: Expected class, delegate,
enum, interface, or struct
c:\...Default.a spx.cs(6,27): error CS1001: Identifier expected
c:\...Default.a spx.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="_Defa ult"
<!--------------- This is the name of your class

So, the code-behind should be like this:

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
}

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

}

Mar 19 '07 #10

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

Similar topics

19
4510
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 that using CSS saves time in the long run, bought a couple books, googled more, read online tutorials, read many posts in this and other groups, etc.
11
3198
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 in the current document is and set the color of the output accordingly? The background will be an image, in most cases. -- Kindly Konrad
1
3306
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 fine, but the background image doesn't continue downward in this column below the links. I tried this in FireFox 1.0.7 and IE6, but this image stops where the last link stops. I want the background all the way to the bottom. How can I force...
7
2765
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
1972
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. My problem now is that on ReadOnly cells the shaded background is not at the top of the cell. I adjust the rectangle Height so that the shading does not drop into the next row.
0
1729
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 exception at FillDatatable dr.AcceptChanges, and also the XTraGridControl will not response when click on the column header to do sorting and filtering. What i'm trying to do is very simple, i just want to retrieve a very large table from web service...
11
2398
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 the table. See an example of the webpage that the script will work with here: http://igorpetrusky.awardspace.com/RunStats.html now, at the top there will be 3 buttons, which will call javascript functions that will operate on tables 2 through N. ...
1
6241
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 to 1, then the color of the row is red, 2 color of the row is green, 3 color yellow, etc. How would I go about doing this.
2
2027
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 merged it into my own, it worked fine with Firefox and Safari but not on IE 7. IE7 displayed the 3rd column but the first two columns were not shown. I was able to reproduce with the original small test by adding a background-color statement to...
0
8984
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.