5 February 2014

Format specific row in Gridview using RowDataBound event

 We can able to do formatting a specific row in a gridview based on some conditions, say for example if price would be more then 100 then display, those rows with background as brown, fore color as black and bold letters.

protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblPrice = (Label)e.Row.FindControl("lblPrice");
                if (Convert.ToInt32(lblPrice.Text) > 100)
                {
                    e.Row.ForeColor = System.Drawing.Color.Black;
                    e.Row.Font.Bold = true;
                    e.Row.BackColor = System.Drawing.Color.Brown;
                }
            }
        }

No comments:

Post a Comment