如何以编程方式格式化 radgrid 单元格

发布于 2024-08-02 10:25:21 字数 109 浏览 2 评论 0原文

我必须根据单元格的值设置 radgrid 单元格的格式(背景色、前景色、字体样式)。

例如 如果该值为负数,则将该单元格的前景色设置为红色。

谁能告诉我如何实现这一目标?

I have to format (backcolor, forecolor, font style) a radgrid's cells depending on the value of the cell.

For example
If the value is negative set the fore color of that cell as red.

Can any one please tell me how this can be achieved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

燃情 2024-08-09 10:25:21
 protected void grdName_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            if (Convert.ToInt32(((DataRowView)item.DataItem)["Column"]) < value)
            {
                TableCell cell = item["Column"];
                cell.BackColor = Color.PeachPuff;
            }
        }
    }
 protected void grdName_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            if (Convert.ToInt32(((DataRowView)item.DataItem)["Column"]) < value)
            {
                TableCell cell = item["Column"];
                cell.BackColor = Color.PeachPuff;
            }
        }
    }
可是我不能没有你 2024-08-09 10:25:21

将 onItemDataBound="Data_OnitemDataBound" 行添加到 aspx 页面中的 radGrid 声明中。

然后将其添加到您的代码后面。 Cells[] 中的数字是您要修改或验证的列的索引。

protected void Data_OnItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        if (Convert.ToDecimal(item.Cells[3].Text) < 0)
        {
            item.Cells[3].ForeColor = System.Drawing.Color.Red;
        }
    }
}

Add the line onItemDataBound="Data_OnitemDataBound" to your radGrid declaration in your aspx page.

Then add this to your code behind. The number in the Cells[] is the index of the column you want to modify or validate against.

protected void Data_OnItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        if (Convert.ToDecimal(item.Cells[3].Text) < 0)
        {
            item.Cells[3].ForeColor = System.Drawing.Color.Red;
        }
    }
}
蓝海 2024-08-09 10:25:21

下面的代码可用于 RadGrid 中的所有单元格。

  protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        foreach (GridDataItem dataItem in RadGridProduct.MasterTableView.Items)
        {
            int cellCount = dataItem.Cells.Count;

            foreach (GridTableCell item in dataItem.Cells)
            {
                if (item.Text == null ||Convert.ToInt32(item.Text) < 0 )
                    item.BackColor = System.Drawing.Color.Brown;
            }

        }

    }

Below code can be used for all the cells in the RadGrid.

  protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        foreach (GridDataItem dataItem in RadGridProduct.MasterTableView.Items)
        {
            int cellCount = dataItem.Cells.Count;

            foreach (GridTableCell item in dataItem.Cells)
            {
                if (item.Text == null ||Convert.ToInt32(item.Text) < 0 )
                    item.BackColor = System.Drawing.Color.Brown;
            }

        }

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文