Coloured rows in datagrid?

1 view
Skip to first unread message

venkii

unread,
Oct 17, 2005, 6:56:05 AM10/17/05
to .NetIndia
Hi

I'm displaying employee data in the datagrid.
I want to coloured the row of employees whose salary is below 5000.

Pl help me!

Thanks in advance......

BabuLives

unread,
Oct 17, 2005, 7:16:32 AM10/17/05
to .NetIndia
Hai..

In Html Page,

<td><font Color ="<%#PickColor(DataBinder.Eval(Container.DataItem ,
"UnitsInStock"))%>">

'Function to pick up the color based on th UnitsInStock Value
Function PickColor(ByVal fldval As Double) As String
Dim color As String
If fldval < 15 Then
color = "Red"
Return color
Else
color = "green"
Return "green"
End If
End Function


For more info..see this..

http://www.c-sharpcorner.com/Code/2003/May/ChangeDataGridColumnColor.asp

http://www.activewidgets.com/javascript.forum.3305.4/how-to-change-row-background.html

(OR)

See this,

protectedvoid dgContacts_ItemDataBound(object source,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
// Make sure that this is a data row and not a header or footer.
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
// Get the value of the manager field.
string isManager = (string)DataBinder.Eval(e.Item.DataItem,
"Manager");

if (isManager == "1")
{
// Set the text and background color.
e.Item.Cells[2].Text = "Manager";
e.Item.BackColor = System.Drawing.Color.AliceBlue;
}
else
{
// Set the text only.
e.Item.Cells[2].Text = "Employee";
}
}
}

Regards,
Satheesh

Reply all
Reply to author
Forward
0 new messages