【问题标题】:Is it Possible to Change the text color for columns in Grid View based upon search item?是否可以根据搜索项更改网格视图中列的文本颜色?
【发布时间】:2012-07-05 09:15:09
【问题描述】:

注意:我需要根据搜索请求更改不同的列。

【问题讨论】:

  • 请解释更多你想要什么
  • 您可能会在这里得到答案 访问stackoverflow.com/questions/4427848/…
  • 您在下面评论中发布的代码,它在页面后面的代码中的什么位置?

标签: c# asp.net .net html


【解决方案1】:

是的,你可以在 GridView.RowDataBound 活动中做到这一点

像这样

protected void yourGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].BackColor = Color.Beige;
            // 0 could be any valid cell index in your row
        }
    }

更多信息Go here

【讨论】:

  • 我需要更改不同页面中特定单元格的背景。我正在报告中这样做。
  • 例如:如果我使用 XYZ 进行搜索,我需要更改该特定单元格的背景颜色。假设如果它在第 1 页和第 10 页我需要更改它,否则如果它在不同的列中也需要更改颜色。但它只发生在第一页。它正在改变其他页面的颜色。
  • 请提供一些和平的代码,这样我就可以理解你做了什么。那会很有帮助。
  • foreach (GridViewRow gr in grdFlowInfo.Rows) { if (gr.RowType == DataControlRowType.DataRow) { for (int i = 0; i < gr.Cells.Count; i++) { if (((Label)gr.Cells[i].Controls[1]).Text.Trim().ToString() == txtSearch.Text.Trim().ToUpper()) { gr.Cells[i].BackColor = System.Drawing.Color.Blue; } } } }
  • 在这段代码中,您遇到的问题是第 10 页的单元格没有着色,但第 1 页的单元格着色,对吗??
猜你喜欢
  • 1970-01-01
  • 2012-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多