.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how to change the bg color of null column in gridview?

Posted By: Rama Krishna     Posted Date: July 07, 2011    Points:5   Category :ASP.Net
i have 1 table emp;A,B,C are employeee names;1,2,3 are emp no;emp A salry is 1000,emp B sal is 2000...emp C sal is not entered .my requirement is how can we change the bg color of particular emp C sal column

Responses
Author: Kemal AL GAZZAH             
Posted Date: July 07, 2011     Points: 20   

You can set the background color of some cells in the gridview_RowDataBound procedure
Here is an example

Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

If e.Row.RowType = ListItemType.Item OrElse e.Row.RowType = ListItemType.AlternatingItem Then
If Session("EstAssurance") = 1 Or Session("EstFiliale") = 1 Then
Else
Dim rv As DataRowView = DirectCast(e.Row.DataItem, DataRowView)
Dim nUnitsInStock As Int32 = Convert.ToInt32(rv.Row.Item(22))
If nUnitsInStock = 1 Then
e.Row.Cells(17).BackColor = Drawing.Color.MediumSeaGreen
' e.Row.Cells(17).ForeColor = Drawing.Color.White
ElseIf nUnitsInStock = 2 Then
e.Row.Cells(17).BackColor = Drawing.Color.Yellow
Else
e.Row.Cells(17).BackColor = Drawing.Color.Tomato ' e.Row.Cells(17).ForeColor = Drawing.Color.White
End If
End If


End If
End Sub

Kemal AL GAZZAH
Author: Kemal AL GAZZAH             
Posted Date: July 07, 2011     Points: 20   

You can set the background color of some cells in the gridview_RowDataBound procedure
Here is an example

Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

If e.Row.RowType = ListItemType.Item OrElse e.Row.RowType = ListItemType.AlternatingItem Then
If Session("EstAssurance") = 1 Or Session("EstFiliale") = 1 Then
Else
Dim rv As DataRowView = DirectCast(e.Row.DataItem, DataRowView)
Dim nUnitsInStock As Int32 = Convert.ToInt32(rv.Row.Item(22))
If nUnitsInStock = 1 Then
e.Row.Cells(17).BackColor = Drawing.Color.MediumSeaGreen
' e.Row.Cells(17).ForeColor = Drawing.Color.White
ElseIf nUnitsInStock = 2 Then
e.Row.Cells(17).BackColor = Drawing.Color.Yellow
Else
e.Row.Cells(17).BackColor = Drawing.Color.Tomato ' e.Row.Cells(17).ForeColor = Drawing.Color.White
End If
End If


End If
End Sub

Kemal AL GAZZAH
Author: Gowthammanju             
Posted Date: July 07, 2011     Points: 20   

u can also use coding as

for changing the colors based on dates


protected void grvOrders_RowDataBound(object sender, GridViewRowEventArgs e)
{
DateTime currDate = Convert.ToDateTime(DateTime.Now.ToString("d"));

if (e.Row.RowType == DataControlRowType.DataRow) {
if (Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "FabDue").ToString()) < currDate) {
e.Row.Cells(0).BorderColor = System.Drawing.Color.Red;
}
if (Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "PartsDue").ToString()) < currDate) {
e.Row.Cells(1).BackColor = System.Drawing.Color.Red;
}
if (Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "AssyDue").ToString()) < currDate) {
e.Row.Cells(2).BackColor = System.Drawing.Color.Red;
}
if (Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "TestDue").ToString()) < currDate) {
e.Row.Cells(3).BackColor = System.Drawing.Color.Red;
}
}
}



u can alter based on ur ideas

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend