Saturday, March 31, 2012
Set Background Color Using Column Value?
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.On Mar 17, 1:26 pm, "TF" <TJForw...@.gmail.com> wrote:
> 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
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.com> wrote:
> it could be the same as in ASP 3:
> bgcolor="#<%=hex_value%>"
> where "hex_value" is a variable
More see here!
http://www.flash50.com/index.php
On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.com> wrote:
> 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
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.com> wrote:
> On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.com> wrote:
>
>
>
>
> 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?
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.com> wrote:
> On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.com> wrote:
>
>
>
>
> 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?
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.com> wrote:
> On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.com> wrote:
>
>
>
>
> 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?
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.com> wrote:
> On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.com> wrote:
>
>
>
>
> 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
On Mar 18, 9:24 pm, "TF" <TJForw...@.gmail.com> wrote:
> On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> 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...............
}
Set Background Color Using Column Value?
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.On Mar 17, 1:26 pm, "TF" <TJForw...@.gmail.comwrote:
Quote:
Originally Posted by
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
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:
Quote:
Originally Posted by
On Mar 17, 1:26 pm, "TF" <TJForw...@.gmail.comwrote:
Quote:
Originally Posted by
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
More see here!
http://www.flash50.com/index.php
On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.comwrote:
Quote:
Originally Posted by
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
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.comwrote:
Quote:
Originally Posted by
On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.comwrote:
>
>
>
Quote:
Originally Posted by
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.
>
Quote:
Originally Posted by
<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>
>
Quote:
Originally Posted by
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?
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.comwrote:
Quote:
Originally Posted by
On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.comwrote:
>
>
>
Quote:
Originally Posted by
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.
>
Quote:
Originally Posted by
<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>
>
Quote:
Originally Posted by
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?
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.comwrote:
Quote:
Originally Posted by
On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.comwrote:
>
>
>
Quote:
Originally Posted by
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.
>
Quote:
Originally Posted by
<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>
>
Quote:
Originally Posted by
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?
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.comwrote:
Quote:
Originally Posted by
On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.comwrote:
>
>
>
Quote:
Originally Posted by
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.
>
Quote:
Originally Posted by
<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>
>
Quote:
Originally Posted by
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
On Mar 18, 9:24 pm, "TF" <TJForw...@.gmail.comwrote:
Quote:
Originally Posted by
On Mar 18, 4:20 am, "Alexey Smirnov" <alexey.smir...@.gmail.comwrote:
>
>
>
>
>
Quote:
Originally Posted by
On Mar 17, 10:26 pm, "TF" <TJForw...@.gmail.comwrote:
>
Quote:
Originally Posted by
Quote:
Originally Posted by
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.
>
Quote:
Originally Posted by
Quote:
Originally Posted by
<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>
>
Quote:
Originally Posted by
Quote:
Originally Posted by
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?
>
Quote:
Originally Posted by
In this case you should rewrite a GridView_RowDataBound event.
>
Quote:
Originally Posted by
Change <asp:GridView ID="GridView1"
OnRowDataBound="GridView1_RowDataBound"...
>
Quote:
Originally Posted by
and add the GridView1_RowDataBound event to your code (code-behind)
>
Quote:
Originally Posted by
C#:
>
Quote:
Originally Posted by
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
>
Quote:
Originally Posted by
if (e.Row.RowType == DataControlRowType.DataRow)
{
string c = e.Row.DataItem["RGBHex"]; // e.g. "#000000"
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(c);
>
Quote:
Originally Posted by
}
}
>
Quote:
Originally Posted by
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...............
}
On Mar 17, 7:26 am, "TF" <TJForw...@.gmail.comwrote:
Quote:
Originally Posted by
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!
Thursday, March 29, 2012
set cell color while rendered in a datagrid
SortExpression="EFF_END_DT" HeaderText="Effective End"
DataFormatString="{0:d}">
<ItemStyle ForeColor= '<% # MyColor(
DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
</asp:BoundColumn>
to have red date is it is over and blue if not!
But I get an error:
Compiler Error Message: BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.TableItemStyle'.
how can I resolve this?i think your trying to user the OnItemDataBound method
In this method you can access each row of your datagrid, and from there
determine if the date should be read or not.
in the .aspx page
<asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....
then in the .cs page
public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
//From here you can access your bound column and set the colors
}
"Ofer" <Ofer@.discussions.microsoft.com> wrote in message
news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
>I use the code: <asp:BoundColumn DataField="EFF_END_DT"
> SortExpression="EFF_END_DT" HeaderText="Effective End"
> DataFormatString="{0:d}">
> <ItemStyle ForeColor= '<% # MyColor(
> DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
> </asp:BoundColumn>
> to have red date is it is over and blue if not!
> But I get an error:
> Compiler Error Message: BC30676: 'DataBinding' is not an event of
> 'System.Web.UI.WebControls.TableItemStyle'.
> how can I resolve this?
>
Thanks! that was helpful.
Would you know why if the results is 2 rows the event fires 4 times
2 times with the value I axpect an 2 with " "
my vb is:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Debug.WriteLine(e.Item.Cells(6).GetType.ToString) 'always
System.Web.UI.WebControls.TableCell
Debug.WriteLine(e.Item.Cells(6).Text)
End Sub
End Class
"Grant Merwitz" wrote:
> i think your trying to user the OnItemDataBound method
> In this method you can access each row of your datagrid, and from there
> determine if the date should be read or not.
> in the .aspx page
> <asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....
> then in the .cs page
> public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
> {
> //From here you can access your bound column and set the colors
> }
>
> "Ofer" <Ofer@.discussions.microsoft.com> wrote in message
> news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
>
>
You can use
If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType = ListItemType.AlternatingItem Then
' Your code here
End If
HTH
Elton Wang
elton_wang@.hotmail.com
>--Original Message--
>Thanks! that was helpful.
>Would you know why if the results is 2 rows the event
fires 4 times
>2 times with the value I axpect an 2 with " "
>my vb is:
> Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
>System.Web.UI.WebControls.DataGridItemEventArgs) Handles
>DataGrid1.ItemDataBound
> Debug.WriteLine(e.Item.Cells
(6).GetType.ToString) 'always
>System.Web.UI.WebControls.TableCell
> Debug.WriteLine(e.Item.Cells(6).Text)
> End Sub
>End Class
>"Grant Merwitz" wrote:
>
datagrid, and from there
OnItemDataBound="MyGrid_OnItemDataBound" ....
DataGridItemEventArgs e)
set the colors
message
69B36E77C458@.microsoft.com...
>'></ItemStyle>
an event of
>.
>
set cell color while rendered in a datagrid
SortExpression="EFF_END_DT" HeaderText="Effective End"
DataFormatString="{0:d}">
<ItemStyle ForeColor= '<% # MyColor(
DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
</asp:BoundColumn>
to have red date is it is over and blue if not!
But I get an error:
Compiler Error Message: BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.TableItemStyle'.
how can I resolve this?i think your trying to user the OnItemDataBound method
In this method you can access each row of your datagrid, and from there
determine if the date should be read or not.
in the .aspx page
<asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....
then in the .cs page
public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
//From here you can access your bound column and set the colors
}
"Ofer" <Ofer@.discussions.microsoft.com> wrote in message
news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
>I use the code: <asp:BoundColumn DataField="EFF_END_DT"
> SortExpression="EFF_END_DT" HeaderText="Effective End"
> DataFormatString="{0:d}">
> <ItemStyle ForeColor= '<% # MyColor(
> DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
> </asp:BoundColumn>
> to have red date is it is over and blue if not!
> But I get an error:
> Compiler Error Message: BC30676: 'DataBinding' is not an event of
> 'System.Web.UI.WebControls.TableItemStyle'.
> how can I resolve this?
Thanks! that was helpful.
Would you know why if the results is 2 rows the event fires 4 times
2 times with the value I axpect an 2 with " "
my vb is:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Debug.WriteLine(e.Item.Cells(6).GetType.ToString) 'always
System.Web.UI.WebControls.TableCell
Debug.WriteLine(e.Item.Cells(6).Text)
End Sub
End Class
"Grant Merwitz" wrote:
> i think your trying to user the OnItemDataBound method
> In this method you can access each row of your datagrid, and from there
> determine if the date should be read or not.
> in the .aspx page
> <asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" ....
> then in the .cs page
> public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
> {
> //From here you can access your bound column and set the colors
> }
>
> "Ofer" <Ofer@.discussions.microsoft.com> wrote in message
> news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
> >I use the code: <asp:BoundColumn DataField="EFF_END_DT"
> > SortExpression="EFF_END_DT" HeaderText="Effective End"
> > DataFormatString="{0:d}">
> > <ItemStyle ForeColor= '<% # MyColor(
> > DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
> > </asp:BoundColumn>
> > to have red date is it is over and blue if not!
> > But I get an error:
> > Compiler Error Message: BC30676: 'DataBinding' is not an event of
> > 'System.Web.UI.WebControls.TableItemStyle'.
> > how can I resolve this?
>
You can use
If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType = ListItemType.AlternatingItem Then
' Your code here
End If
HTH
Elton Wang
elton_wang@.hotmail.com
>--Original Message--
>Thanks! that was helpful.
>Would you know why if the results is 2 rows the event
fires 4 times
>2 times with the value I axpect an 2 with " "
>my vb is:
> Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
>System.Web.UI.WebControls.DataGridItemEventArgs) Handles
>DataGrid1.ItemDataBound
> Debug.WriteLine(e.Item.Cells
(6).GetType.ToString) 'always
>System.Web.UI.WebControls.TableCell
> Debug.WriteLine(e.Item.Cells(6).Text)
> End Sub
>End Class
>"Grant Merwitz" wrote:
>> i think your trying to user the OnItemDataBound method
>>
>> In this method you can access each row of your
datagrid, and from there
>> determine if the date should be read or not.
>>
>> in the .aspx page
>> <asp:DataGrid id="MyGrid"
OnItemDataBound="MyGrid_OnItemDataBound" ....
>>
>> then in the .cs page
>>
>> public void MyGrid_OnItemDataBound(object Sender,
DataGridItemEventArgs e)
>> {
>> //From here you can access your bound column and
set the colors
>> }
>>
>>
>> "Ofer" <Ofer@.discussions.microsoft.com> wrote in
message
>> news:574957A7-2D07-44A7-95BD-
69B36E77C458@.microsoft.com...
>> >I use the code: <asp:BoundColumn DataField="EFF_END_DT"
>> > SortExpression="EFF_END_DT" HeaderText="Effective End"
>> > DataFormatString="{0:d}">
>> > <ItemStyle ForeColor= '<% # MyColor(
>> > DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%
>'></ItemStyle>
>> > </asp:BoundColumn>
>> > to have red date is it is over and blue if not!
>> > But I get an error:
>> > Compiler Error Message: BC30676: 'DataBinding' is not
an event of
>> > 'System.Web.UI.WebControls.TableItemStyle'.
>>> > how can I resolve this?
>>>>
>>
>>
>.
Thursday, March 22, 2012
Set formatting (color) on a literal or label
news (in red). Is there a way to do this for a single literal or label? Or do
we need to have two, one set to green and one to red and just set one to a
text string and the other to ""?
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.comDim GoodNews as Boolean
....
If GoodNews Then
MessageLabel.Font.Color = Color.Green
Else
MessageLabel.Font.Color = Color.Red
End If
"David Thielen" <thielen@.nospam.nospam> wrote in message
news:5D81CB86-10F8-471F-A5E7-00E187DABF4B@.microsoft.com...
> We have a status message we display that can be good news (in green) or
> bad
> news (in red). Is there a way to do this for a single literal or label? Or
> do
> we need to have two, one set to green and one to red and just set one to a
> text string and the other to ""?
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
If you do it using a Literal you can set the Text property to the complete
markup e.g.
If GoodNews Then
Literal1.Text = "<span class='greencolorCss'>this is the status
for good news </span>"
Else
Literal1.Text = "<span class='redcolorCss'>this is the status
for bad news </span>"
End If
If you do it using a Label you might write:
If GoodNews Then
Label1.CssClass = "greencolorCss"
Label1.Text = "This is the status for good news"
Else
Label1.CssClass = "redcolorCss"
Label1.Text = "This is the status for bad news"
End If
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"David Thielen" wrote:
> We have a status message we display that can be good news (in green) or bad
> news (in red). Is there a way to do this for a single literal or label? Or do
> we need to have two, one set to green and one to red and just set one to a
> text string and the other to ""?
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com