【问题标题】:asp.net grid color settingasp.net网格颜色设置
【发布时间】:2010-06-11 21:57:35
【问题描述】:

我有一个绑定到数据表的gridview。绑定完成后如何以编程方式更改第一列的颜色?

【问题讨论】:

  • “绑定后”是什么意思?如果是“绑定后”,则渲染完成。

标签: asp.net gridview asp.net-controls


【解决方案1】:

您必须在 RowDataBound 事件中发生绑定时执行此操作。

设置事件中第一列单元格的颜色:

protected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[0].BackColor = Color.Red
}

【讨论】:

    【解决方案2】:

    一种方法是处理“OnRowCreated”事件。您可以通过在 .aspx 中添加此 Gridview 声明来做到这一点,如下所示:

    <asp:GridView ID="GridView1" runat="server" OnRowCreated="GridView1_RowCreated" />
    

    然后您可以逐行引用单元格 - 这会将列的背景颜色设置为蓝色。

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[1].BackColor = System.Drawing.Color.Blue;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多