【问题标题】:How to change the gridview row color?如何更改gridview行颜色?
【发布时间】:2014-03-08 16:12:37
【问题描述】:

我有我的代码来更改 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; }

}

【问题讨论】:

  • 试试this。参考 SelectedRow 后,您可以轻松更改其颜色

标签: c# asp.net gridview


【解决方案1】:

我是在网格的 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;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    相关资源
    最近更新 更多