我有我的代码来更改 GridView 背景颜色中的行 状态完成。我很好地完成了我的代码,但它不起作用。
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; }
}
答案 0 :(得分:0)
我是在网格的rowdatabound事件上做的
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;
}
}