Sneha Panda
how to change row background color in gridview
By Sneha Panda in .NET on Dec 15 2014
  • varsha dodiya
    Dec, 2014 30

    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Aqua;

    • 2
  • Nitin Choudhary
    Jan, 2015 16

    if (e.Row.RowType = DataControlRowType.DataRow) {//Check your condition here, Cells[1] for ex. is DONE/Not Done column If(e.Row.Cells[1].Text == "DONE"){e.Row.BackColor = Drawing.Color.Green // This will make row back color green} }

    • 1
  • varsha dodiya
    Dec, 2014 30

    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Aqua;

    • 1
  • Jiyaul Mustapha
    Jul, 2019 11

    protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    Label lbl_Code = (Label)e.Row.FindControl(“lblCode”);
    if (lbl_Code.Text == “1”)
    {
    e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml(“#f2d9d9”);
    }
    }
    }

    • 0
  • Vamsi Krishna
    Oct, 2015 7

    In data bound event if (e.Row.RowType = DataControlRowType.DataRow) {e.Row.BackColor = System.Drawing.Color.Orange; }

    • 0
  • Narasimha Reddy Chennupalli
    Jun, 2015 25

    You can change row background color in OnRowDataBound event of Gridview. Steps: 1.create OnRowDataBound event. protected void grd_OnRowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow){ //do something } } 2. Find particular row which you want change the background color of Grid. String dept=e.Row.Cells[1].Text ; 3. Write the condition for checking the value. Example is there is Department column, check the value is IT or not. If(dept=="IT") 4. If value is OT then assign background color for that row. Ex:- e.Row.BackgroundColor=System.Drawing.Colo}

    • 0
  • Pankaj  Kumar Choudhary
    May, 2015 27

    protected void gvReviewAnswer_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {string User_Answer = (string)DataBinder.Eval(e.Row.DataItem, "User_Answer"); string CorrectAnswer = (string)DataBinder.Eval(e.Row.DataItem, "CorrectAnswer"); if (User_Answer == "0000") { e.Row.BackColor = System.Drawing.Color.PaleGoldenrod;} else if (User_Answer == CorrectAnswer) { e.Row.BackColor = System.Drawing.Color.PaleGreen;} else if (User_Answer != CorrectAnswer) { e.Row.BackColor = System.Drawing.Color.Pink;}}

    • 0
  • Nitin Choudhary
    Jan, 2015 16

    protected void OnRowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow){int quantity = int.Parse(e.Row.Cells[1].Text);foreach (TableCell cell in e.Row.Cells){if (quantity == 0){cell.BackColor = Color.Red;}if (quantity > 0 && quantity <= 50){cell.BackColor = Color.Yellow;}if (quantity > 50 && quantity <= 100){cell.BackColor = Color.Orange;}}} }

    • 0
  • Naresh
    Jan, 2015 13

    gridviewid.rows[e.selectindex].backcolor=system.drawing.color.desiredcolor

    • 0
  • Munesh Sharma
    Jan, 2015 7

    http://www.aspsnippets.com/Articles/Dynamically-change-GridView-Row-Background-Color-based-on-condition-in-ASPNet-using-C-and-VBNet.aspx

    • 0
  • Sarath Kumar
    Jan, 2015 4

    By using we can call RowDataBound Event.or else we can assign directly in aspx page.

    • 0
  • Vithal Wadje
    Dec, 2014 31

    refer my article http://www.c-sharpcorner.com/UploadFile/0c1bb2/highlighting-particular-row-of-gridview-in-specific-conditio/

    • 0
  • Nayeem Mansoori
    Dec, 2014 22

    Create GridView1_RowDataBound event for your GridView. if (e.Row.RowType == DataControlRowType.DataRow) {//Check your condition here//Get Id from here and based on Id check value in the //underlying dataSource Row where you have "DONE" column value// e.g.// (gridview.DataSource as DataTable), now you can find your row and cell // of "Done"If(Condition True){e.Row.BackColor = Drawing.Color.Red; // your color settings } }

    • 0
  • Khargesh Rajput
    Dec, 2014 22

    protected void gvReviewAnswer_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {string User_Answer = (string)DataBinder.Eval(e.Row.DataItem, "User_Answer");string CorrectAnswer = (string)DataBinder.Eval(e.Row.DataItem, "CorrectAnswer");if (User_Answer == "0000") {e.Row.BackColor = System.Drawing.Color.PaleGoldenrod;} else if (User_Answer == CorrectAnswer) {e.Row.BackColor = System.Drawing.Color.PaleGreen;} else if (User_Answer != CorrectAnswer) {e.Row.BackColor = System.Drawing.Color.Pink;}}

    • 0
  • Pankaj Pandey
    Dec, 2014 19

    use the css background-color=#aabbcc;

    • 0
  • Sneha Panda
    Dec, 2014 15

    We can change by using javascript function and direct command also1. document.getElementById(row).style.backgroundColor = "#ffffda"; GridView1_RowDataBound evente.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" & e.Row.ClientID & "')");2. Create GridView1_RowDataBound event for your GridView. if (e.Row.RowType == DataControlRowType.DataRow) {If(Condition True){e.Row.BackColor = Drawing.Color.Red; } }foreach (TableCell cell in e.Row.Cells){if (D_inshed >= 6){cell.BackColor = System.Drawing.Color.Orange;}}

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS