【发布时间】:2020-05-20 20:39:24
【问题描述】:
我需要根据条件为网格列设置颜色。 例如:我在网格中有两个字段 1.销售价格 2. 新销售 如果销售价格和新销售价值相同,我想显示绿色 否则,如果销售价格高于新销售,则显示红色 否则,如果销售价格低于新销售,则希望显示黄色。
这不是一个通用的查询屏幕,这就像在标题中使用 FormDetal 模板的处理屏幕我有一些过滤器值基于我的网格数据将被加载,我将修改价格字段,如上面提到的示例“新销售”我将修改的字段是未绑定的字段“销售”字段已绑定
所以在网格的行项目中,如果修改新销售,则需要比较销售和新销售,如果两个值相同,那么特别是对于 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">
提前致谢。
【问题讨论】: