1-Here is the code in VB.NET 2005/2008
The name i gave empGrid to the datagrid.To do this go the property of datagrid and
click on the events section and double click on ItemDataBound event and add the code.
Protected Sub empGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles empGrid.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim Status As String = Convert.ToString(drv.Row.Item("Status"))
If Status = "Active" Then
e.Item.Cells(4).BackColor = Drawing.Color.Green
ElseIf Status = "Inactive" Then
e.Item.Cells(4).BackColor = Drawing.Color.Red
End If
End If
End Sub
1-Here is the code in C# 2005/2008
The name i gave empGrid to the datagrid.To do this go the property of datagrid and
click on the events section and double click on ItemDataBound event and add the code.
private void empGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView Drv = (DataRowView)e.Item.DataItem;
// Get fourth column value.The coloumn needed
String Status = Convert.ToString(rv.Row.ItemArray[4]);
if (Status =="Active")
{
e.Item.Cells[4].BackColor = Color.Green;
}
//Just add the remaining steps
}
}
This code is free like "Free Coffee"
Talley Ouro
No comments:
Post a Comment