Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cell color based on field value

Status
Not open for further replies.

thetickisme

Programmer
Oct 19, 2005
12
US
How can I change a grids cell color based on another fields value in Dreamweaver MX and VB?

THnaks
 
Use an if statement
Code:
<%
if value = value1 then
strcolour = "red"
else
strcolour = "blue"
%>
<td bgcolor="<%=strcolour%>">

Cheech

[Peace][Pipe]
 
Thanks! I keep getting code blocks are not supported in this context .. Hint's? Please
 
?show us a bit of code?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Since I am lost anyways<G> I went after it another way but I am still wondering around Lost.

<ItemTemplate><%# DataSet1.FieldValue("Curr_Qtr", Container) %><%# DataBinder.Eval(Container.DataItem, "Curr_Qtr") %>' ForeColor='<%# IIF(DataBinder.Eval(Container.DataItem, "Qtr_Plus_1") = DataBinder.Eval(Container.DataItem, "Qtr_Plus_2"), "Black", "Blue) %>'/></ItemTemplate>
</asp:TemplateColumn>

I was testing above to see if I could change the color of a cell based on another cells color - call idt practice ok<G>

My end goal is to change a cell color based on the value in it. if it's STOP then turn the cell red if WARNING turn cell Yellow.

Here's my stock code

<asp:TemplateColumn HeaderText="Curr_Qtr"
Visible="True">
<ItemTemplate><%# DataSet1.FieldValue("Curr_Qtr", Container) %></ItemTemplate>
</asp:TemplateColumn>

thanks for putting up with me!

 
Here is how I got it to work -with help - so if anyone else needs a snip of working color the cell based on data here you go. And thank you for all of the help.

<script runat="server">
Sub Datagrid1_ItemDataBound(source As Object, e As DataGridItemEventArgs)
If (e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem) Then
If e.Item.DataItem("Curr_Qtr") = "Stop" Then _
e.Item.Cells(2).BackColor = System.Drawing.Color.DeepPink
End If
End Sub

</script>




<asp:DataGrid OnItemDataBound="DataGrid1_ItemDataBound"
AllowCustomPaging="true"
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
DataSource="<%# DataSet1.DefaultView %>" id="DataGrid1"
PagerStyle-Mode="NextPrev"
PagerStyle-NextPageText="Next"
PagerStyle-PrevPageText="Previous"
PagerStyle-Position="TopAndBottom"
PagerStyle-HorizontalAlign="Center"

PageSize="<%# DataSet1.PageSize %>"
runat="server"
ShowFooter="true"
ShowHeader="true"
OnPageIndexChanged="DataSet1.OnDataGridPageIndexChanged"
VirtualItemCount="<%# DataSet1.RecordCount %>"
OnSortCommand="chSortGrid">
 
Here's a snip of all of the values it does

Sub Datagrid1_ItemDataBound(source As Object, e As DataGridItemEventArgs)
If (e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem) Then
If e.Item.DataItem("Curr_Qtr") = "Stop" Then _
e.Item.Cells(7).BackColor = System.Drawing.Color.Red
If e.Item.DataItem("Curr_Qtr") = "Warning" Then _
e.Item.Cells(7).BackColor = System.Drawing.Color.Yellow
If e.Item.DataItem("Curr_Qtr") = "Caution" Then _
e.Item.Cells(7).BackColor = System.Drawing.Color.Orange
If e.Item.DataItem("Curr_Qtr") = "Go" Then _
e.Item.Cells(7).BackColor = System.Drawing.Color.Green
If e.Item.DataItem("Qtr_Plus_1") = "Stop" Then _
e.Item.Cells(8).BackColor = System.Drawing.Color.Red
If e.Item.DataItem("Qtr_Plus_1") = "Warning" Then _
e.Item.Cells(8).BackColor = System.Drawing.Color.Yellow
If e.Item.DataItem("Qtr_Plus_1") = "Caution" Then _
e.Item.Cells(8).BackColor = System.Drawing.Color.Orange
If e.Item.DataItem("Qtr_Plus_1") = "Go" Then _
e.Item.Cells(8).BackColor = System.Drawing.Color.Green
If e.Item.DataItem("Qtr_Plus_2") = "Stop" Then _
e.Item.Cells(9).BackColor = System.Drawing.Color.Red
If e.Item.DataItem("Qtr_Plus_2") = "Warning" Then _
e.Item.Cells(9).BackColor = System.Drawing.Color.Yellow
If e.Item.DataItem("Qtr_Plus_2") = "Caution" Then _
e.Item.Cells(9).BackColor = System.Drawing.Color.Orange
If e.Item.DataItem("Qtr_Plus_2") = "Go" Then _
e.Item.Cells(9).BackColor = System.Drawing.Color.Green
If e.Item.DataItem("Qtr_Plus_3") = "Stop" Then _
e.Item.Cells(10).BackColor = System.Drawing.Color.Red
If e.Item.DataItem("Qtr_Plus_3") = "Warning" Then _
e.Item.Cells(10).BackColor = System.Drawing.Color.Yellow
If e.Item.DataItem("Qtr_Plus_3") = "Caution" Then _
e.Item.Cells(10).BackColor = System.Drawing.Color.Orange
If e.Item.DataItem("Qtr_Plus_3") = "Go" Then _
e.Item.Cells(10).BackColor = System.Drawing.Color.Green
If e.Item.DataItem("Qtr_Plus_4") = "Stop" Then _
e.Item.Cells(11).BackColor = System.Drawing.Color.Red
If e.Item.DataItem("Qtr_Plus_4") = "Warning" Then _
e.Item.Cells(11).BackColor = System.Drawing.Color.Yellow
If e.Item.DataItem("Qtr_Plus_4") = "Caution" Then _
e.Item.Cells(11).BackColor = System.Drawing.Color.Orange
If e.Item.DataItem("Qtr_Plus_4") = "Go" Then _
e.Item.Cells(11).BackColor = System.Drawing.Color.Green
If e.Item.DataItem("Qtr_Plus_5") = "Stop" Then _
e.Item.Cells(12).BackColor = System.Drawing.Color.Red
If e.Item.DataItem("Qtr_Plus_5") = "Warning" Then _
e.Item.Cells(12).BackColor = System.Drawing.Color.Yellow
If e.Item.DataItem("Qtr_Plus_5") = "Caution" Then _
e.Item.Cells(12).BackColor = System.Drawing.Color.Orange
If e.Item.DataItem("Qtr_Plus_5") = "Go" Then _
e.Item.Cells(12).BackColor = System.Drawing.Color.Green
End If
End Sub

2 year forcast of software DONE!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top