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

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Gridview set Forecolor

Posted By:Deco       Posted Date: October 31, 2010    Points: 15    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This code snippet will help you to set fore color for the particular column, based on it's value

The below code will make the forecolor of the column value to Red when the employee salary is less than 2000

protected void Page_Load(object sender, EventArgs e)
            SqlConnection cn = new SqlConnection("Persist Security Info=False;User ID=sa;password=sa;Initial Catalog=Adsingh;Data Source=.");
            SqlDataAdapter cmd = new SqlDataAdapter("Select Designation, Salary from Employee", cn);
            DataSet ds = new DataSet();
            GridView1.DataSource = ds;

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)


        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)
if (Int32.Parse(e.Row.Cells[1].Text) < 2000)
                    e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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