如何在Acumatica中有条件地设置特定列字段值的颜色 [英] How can we set color for particular column filed value conditionally in Acumatica

查看:14
本文介绍了如何在Acumatica中有条件地设置特定列字段值的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,需要根据条件设置网格栏的颜色。 例如:我在网格中有两个字段 1.销售价格 2.新销售 如果销售价格和新销售价值相同,我想显示绿色 如果销售价格高于新销售,则想要显示红色 如果销售价格低于新销售,则希望显示黄色。

这不是一个通用的查询屏幕,这就像在标题中使用FormDetal模板处理屏幕一样,我有一些筛选值基于我的网格数据将被加载到上面,我将修改上面提到的价格字段。我将修改"New Sales"字段,它是未绑定的字段"Sales"字段被绑定

因此,在网格的行项中,如果Modify new Sales,则需要比较Sales和New Sales,如果两者的值相同,则特别是对于NewSales字段,我需要显示绿色。

我在页面文件中尝试了以下代码,但在调试时没有调用此Grid1_RowDataBound事件

protected void Page_Load(object sender, EventArgs e)
    {
        //Create needed styles here
        Style style = new Style();
        style.Font.Bold = true;
        this.Page.Header.StyleSheet.CreateStyleRule(style, this, "." + "BoldText");

        Style style1 = new Style();
        style1.ForeColor = System.Drawing.Color.FromArgb(50, 180, 50);
        this.Page.Header.StyleSheet.CreateStyleRule(style1, this, "." + "GreenColor");
    }

    protected void grid1_RowDataBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
    {
        // Take DataItem and convert it to your DAC object type
        // KWUpdateStylePricing is my DAC name
        KWUpdateStylePricing row = e.Row.DataItem as KWUpdateStylePricing;
        if (row != null && row.WholeSalePrice == row.NewWholeSalePrice)
        {
            e.Row.Style.CssClass = "GreenColor";
        }
    }

ASPX页面网格属性

<px:PXGrid ID="grid1" runat="server" DataSourceID="ds" Style="z-index: 100; left: 0px; top: 0px; height: 385px;" Width="100%" NoteIndicator="false" FilesIndicator="false"
        BorderWidth="0px" OnRowDataBound="grid1_RowDataBound" SkinID="DetailsInTab" SyncPosition="True" StatusField="MyAvailability" RepaintColumns="true" Height="385px" TabIndex="7700" AllowPaging="true" AdjustPageSize="Auto" AllowSearch="true" AllowAutoHide="false">

提前谢谢。

推荐答案

为类分配行时遇到问题。因此,我将行单元格分配给一个对象,然后执行我的逻辑。尝试类似下面的代码,看看它是否有效。

protected void grid_RowDataBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
{
    Object wholesaleprice = e.Row.Cells["WholeSalePrice"].Value;
    Object newwholesaleprice = e.Row.Cells["NewWholeSalePrice"].Value;

    if (wholesaleprice != null 
        && newwholesaleprice != null
        && ((decimal)wholesaleprice) == ((decimal)newwholesaleprice))
    {
        e.Row.Style.CssClass = "GreenColor";
    }
}

这篇关于如何在Acumatica中有条件地设置特定列字段值的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆