|
| |
|
|
scpigksin
Posts: 10 Joined: 11/19/2007 Status: offline
|
ASPX Datagrid - Changing background color - 10/13/2009 17:23:09
Objective When the Year changes from 2008 to 2007 to 2006 etc. etc......I want to change the background color to show the different years. Web Page http://scfootballhistory.com/test.aspx?schoolid=148 Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Untitled 1</title> </head> <body> <form id="form1" runat="server"> <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" > <Columns> <asp:boundfield DataField="Year" HeaderText="Year" SortExpression="Year"> </asp:boundfield> <asp:boundfield DataField="Week" HeaderText="Week" SortExpression="Week"> </asp:boundfield> <asp:boundfield DataField="Team" HeaderText="Team" SortExpression="Team"> </asp:boundfield> <asp:boundfield DataField="Score" HeaderText="Score" SortExpression="Score"> </asp:boundfield> <asp:boundfield DataField="Opponent" HeaderText="Opponent" SortExpression="Opponent"> </asp:boundfield> <asp:boundfield DataField="Score2" HeaderText="Score2" SortExpression="Score2"> </asp:boundfield> <asp:boundfield DataField="Result" HeaderText="Result" SortExpression="Result"> </asp:boundfield> <asp:boundfield DataField="Round" HeaderText="Round" SortExpression="Round"> </asp:boundfield> </Columns> </asp:GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="fpdb/Playoffs.mdb" SelectCommand="SELECT [Year], [Date], [Week], [Team], [Score], [Opponent], [Score2], [Type], [Result], [Round] FROM [Playoffs] WHERE ([SchoolID] = ?) ORDER BY [Year] DESC, [Week]"> <SelectParameters> <asp:querystringparameter Name="SchoolID" QueryStringField="SchoolID" Type="String" /> </SelectParameters> </asp:AccessDataSource> </form> </body> </html> ============= Thank you very much for any assistance.
|
|
|
|
BeTheBall
Posts: 6502 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: ASPX Datagrid - Changing background color - 10/14/2009 22:37:52
Are you looking for different colors for every year or just two colors which alternate each time the year changes? Second, are you coding with C# or VB?
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
scpigksin
Posts: 10 Joined: 11/19/2007 Status: offline
|
RE: ASPX Datagrid - Changing background color - 10/18/2009 19:32:20
I just need the color to change everytime the years changes. It could be 2 colors alternating. I am using VB. Thanks and sorry for the delay.....weekend full of football.
|
|
|
|
BeTheBall
Posts: 6502 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: ASPX Datagrid - Changing background color - 10/21/2009 23:08:05
See if this works for you. <%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim drv As System.Data.DataRowView = DirectCast(e.Row.DataItem, System.Data.DataRowView)
If Integer.Parse(drv("Year")) Mod 2 = 0 Then ' First Row
' Handle the first row by initializing our page level variable
e.Row.BackColor = Drawing.Color.Yellow
Else ' All other rows
e.Row.BackColor = Drawing.Color.Red
End If
End If
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:boundfield DataField="Year" HeaderText="Year" SortExpression="Year">
</asp:boundfield>
<asp:boundfield DataField="Week" HeaderText="Week" SortExpression="Week">
</asp:boundfield>
<asp:boundfield DataField="Team" HeaderText="Team" SortExpression="Team">
</asp:boundfield>
<asp:boundfield DataField="Score" HeaderText="Score" SortExpression="Score">
</asp:boundfield>
<asp:boundfield DataField="Opponent" HeaderText="Opponent" SortExpression="Opponent">
</asp:boundfield>
<asp:boundfield DataField="Score2" HeaderText="Score2" SortExpression="Score2">
</asp:boundfield>
<asp:boundfield DataField="Result" HeaderText="Result" SortExpression="Result">
</asp:boundfield>
<asp:boundfield DataField="Round" HeaderText="Round" SortExpression="Round">
</asp:boundfield>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="fpdb/Playoffs.mdb" SelectCommand="SELECT [Year], [Date], [Week], [Team], [Score], [Opponent], [Score2], [Type], [Result], [Round] FROM [Playoffs] WHERE ([SchoolID] = ?) ORDER BY [Year] DESC, [Week]">
<SelectParameters>
<asp:querystringparameter Name="SchoolID" QueryStringField="SchoolID" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
</form>
</body>
</html>
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|