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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting colours in datagrid

Status
Not open for further replies.

rac55

Programmer
Jul 1, 2003
62
AU
Hi

Does anyone know how to set certain columns in a datagrid to a different colour? Basically I need to set set the column 'result' to red when it is a a certain value ie. pass or fail

My code is;

<asp:DataGrid id="MyDataGrid" runat="server" align="center" BorderWidth="5px" Cellpadding="5" autoGenerateColumns="False" Font-Size="Small" BorderColor="#000099" ForeColor="Black" OnSelectedIndexChanged="MyDataGrid_SelectedIndexChanged">
<HeaderStyle font-size="X-Small" font-bold="True"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="ModuleNo" HeaderText="MODULE NO"></asp:BoundColumn>
<asp:BoundColumn DataField="ModuleTitle" HeaderText="MODULE TITLE"></asp:BoundColumn>
<asp:BoundColumn DataField="ScotLevel" HeaderText="SCOT LEVEL"></asp:BoundColumn>
<asp:BoundColumn DataField="ScotcatCredit" HeaderText="SCOTCAT CREDIT"></asp:BoundColumn>
<asp:BoundColumn DataField="Attempt" HeaderText="ATTEMPT"></asp:BoundColumn>
<asp:BoundColumn DataField="AggregateExam" HeaderText="AGGREGATE EXAM"></asp:BoundColumn>
<asp:BoundColumn DataField="AggregateCW" HeaderText="AGGREGATE CW"></asp:BoundColumn>
<asp:BoundColumn DataField="Grade" HeaderText="GRADE"></asp:BoundColumn>
<asp:BoundColumn DataField="Result" HeaderText="RESULT"></asp:BoundColumn>
</Columns>
</asp:DataGrid>

Thanks
 
Taken from datagridgirl's website
Really great website by the way

Sub Datagrid1_ItemDataBound(source As Object, e As DataGridItemEventArgs)
If (e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem) Then
If Convert.ToDateTime(e.Item.Cells(1).Text) < DateTime.Today Then _
e.Item.Cells(1).BackColor = System.Drawing.Color.FromName("#ffccff")
If e.Item.DataItem("UserID") = 590 Then _
e.Item.Cells(2).BackColor = System.Drawing.Color.DeepPink
End If
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top