如何设置列属性(DisplayFormatString是precise)一个ASPX(devEx preSS)从code格背后的? [英] How can I set the column properties(DisplayFormatString to be precise) of a aspx(devExpress) grid from code behind?

查看:739
本文介绍了如何设置列属性(DisplayFormatString是precise)一个ASPX(devEx preSS)从code格背后的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个aspx(devex preSS)的网格。使用我生成动态地从code behind.Below列是从我grid_databinding事​​件code。

I have an aspx(devexpress) grid. Using which I generate columns dynamically from code behind.Below is the code from my grid_databinding event.

GridViewDataTextColumn bfield = new GridViewDataTextColumn();
if (TestString.YearSelectedNames.ToString().Length > 4)
{  string colName = string.Empty;
if (iCount % 2 == 0)
  {

   colName = TestString.YearSelectedNames.ToString().Substring(5, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString();
   bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
  }
  else
     {
     colName = TestString.YearSelectedNames.ToString().Substring(0, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString().Replace('1', ' ');
     bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
     }

}
else
    {
    bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
    }
    bfield.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
    bfield.HeaderStyle.Wrap = DevExpress.Utils.DefaultBoolean.True;
    bfield.Name = dtFreezing.Columns[iCount].ColumnName.Trim();
    bfield.Width = Unit.Pixel(120);
    bfield.VisibleIndex = iCount;
    bfield.DataItemTemplate = new DevxGridViewTemplate(ListItemType.Item, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
    bfield.CellStyle.HorizontalAlign = HorizontalAlign.Right;
    bfield.PropertiesTextEdit.DisplayFormatString = "N2";
    gridViewProductCrop.Columns.Add(bfield);

code,这里的行

Here the line of code

bfield.PropertiesTextEdit.DisplayFormatString = "N2";

在这里我想设置网格列的财产小数点后只显示两位小数。

is where I am trying to set the property of the grids' column to display only two decimals after the decimal point.

code此行似乎并没有摆在首位的工作。

This line of code doesn't seem to work in the first place.

我甚至用尝试{0:0.00}{0:N2},但白白

I have even tried using "{0:0.00}" and "{0:N2}" but in vain

可能的原因是,我写这行code在网格的数据绑定事件。但我还能怎么设置从code柱后面的属性。

Possible reason being that I am writing this line of code in the grid's databinding event. But how else can I set the column properties from code behind

推荐答案

尝试改变这个code

Try to change this code

bfield.PropertiesTextEdit.DisplayFormatString = "N2";

this.PropertiesTextEdit.DisplayFormatString = "N2";

我觉得这种事情发生怎么把ü循环对象(做一个新的对象)和属性会改写。

i think this happen coz u loop the object(make a new object) and the properties would be overwrite.

CMIIW

这篇关于如何设置列属性(DisplayFormatString是precise)一个ASPX(devEx preSS)从code格背后的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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