[英]How to change the gridview row color?
當狀態為“完成”時,我有代碼來更改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; }
}
我在網格的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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.