0

I have my code to change the row in GridView background color when the status Done. I did my code well but it doesn't work.

protected void status_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddlStatus = (DropDownList)sender;


    string someVariable1 = ddlStatus.SelectedItem.Text; // gets the Text displayed
    string someVariable2 = ddlStatus.SelectedItem.Value; // gets the Value 

    GridViewRow row = (GridViewRow)ddlStatus.NamingContainer;


    if (someVariable1 == "Done")
    { row.BackColor = System.Drawing.Color.Red; }

}
Zafar
  • 3,394
  • 4
  • 28
  • 43
Egydeveloper
  • 195
  • 1
  • 4
  • 19
  • Try [this](http://stackoverflow.com/questions/20982398/click-gridview-find-selected-row). Once you have reference to the SelectedRow you can change the color on it easily – deostroll Mar 08 '14 at 16:28

1 Answers1

0

I do it on the rowdatabound event of the grid

protected void Grid_RowDataBound(Object sender, GridViewRowEventArgs e) {
    string someVariable1 = Convert.ToString((Grid.Rows[0].Cells["comboCell"] as DataGridViewComboBoxCell).FormattedValue.ToString());

    if(e.Row.RowType == DataControlRowType.DataRow) {
         if(someVariable1 == "Done")
             e.Row.BackColor = Color.Green;
    }
}
francorobles
  • 41
  • 1
  • 7