15
Reply

how to change row background color in gridview

Sneha Panda

Sneha Panda

Dec 15, 2014
4.4k
0

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

    varsha dodiya
    December 30, 2014
    2

    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} }

    Nitin Choudhary
    January 16, 2015
    1

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

    varsha dodiya
    December 30, 2014
    1

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

    Vamsi Krishna
    October 07, 2015
    0

    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}

    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;}}

    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;}}} }

    Nitin Choudhary
    January 16, 2015
    0

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

    Naresh
    January 13, 2015
    0

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

    Munesh Sharma
    January 07, 2015
    0

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

    Sarath Kumar
    January 04, 2015
    0

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

    Vithal Wadje
    December 31, 2014
    0

    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 } }

    Nayeem Mansoori
    December 22, 2014
    0

    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;}}

    Khargesh Rajput
    December 22, 2014
    0

    use the css background-color=#aabbcc;

    Pankaj Pandey
    December 19, 2014
    0

    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;}}

    Sneha Panda
    December 15, 2014
    0