Sunday, August 2, 2009
How to color a row of DataGrid in ASP.NET 2.0/3.5
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
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2009
(28)
-
▼
August
(18)
- CRUD operations with LINQ To SQL(ASP.NET 3.5)
- Do you know the Best developers IDE?
- Do you know which version of AJAX Toolkit to use f...
- XScheduler will be release end September 2009 eas...
- How to get the current Primary Key from GridView(A...
- New To LINQ To SQL?Watch this video
- Introduction to Windows Live Cloud Services
- How to bind XML Data to GridView or DataGrid?
- Free HTML control for your VS 2005/2008 Projects
- How to configure Visual Studio 2005/2008 to use En...
- How to Enable Administrator Account on Vista
- Best VB.NET 2005/2008 Books
- SQL Server 2005 Authentication
- Solution to this error:Maximum stored procedure, f...
- Useful JavaScripts for DataGrid control
- How to hack "Failed to query a list of database na...
- Code to add JavaScript confirmation dialog to a bu...
- How to color a row of DataGrid in ASP.NET 2.0/3.5
-
▼
August
(18)
About Me
- TALLEY
- Raleigh, NC, United States
- I am a software developer based in Raleigh,NC,USA.I design softwares and systems ;i also do consulting for companies worldwide.I program with these languages:VB.NET 2003/2005/2008;C#;Java(fun),SQL(200,2005,2008);ASP.NET 2.0/3.5;ASP.NET AJAX;ASP.NET MVC;JavaScript;JQuery;Windows Workflow Foundation;Web Services.I have 4 years + in programming.
No comments:
Post a Comment