在ASPxGridView中设置单个值

时间:2015-07-01 19:53:06

标签: c# asp.net webforms devexpress

我有一个从数据库填充的ASPxGridView。我的代码中的所有内容都能正常工作(大约95%对此确定)并且我基本上想要调用

e.SetValue("MeanTime") = meanTimeCell;

不幸的是,这不存在。我搜索过这个但找不到答案。

protected void RTMonitoringGrid_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
     if (e.RowType == DevExpress.Web.GridViewRowType.Data) 
     {
        //this gets a value in the GridView 
        string meanTimeCell = e.GetValue("MeanTime").ToString();

        try
        {
           double result;
           if (double.TryParse(meanTimeCell, out result))
           {  
              //this is the string I essentially want to overwrite the old cell data with
              meanTimeCell = string.Format("{0}s", Math.Round(result, 1));
              //SetValue would be called here
           }
        }
        catch (Exception ex)
        {

        }
     }
}

有没有人知道一个简单的解决方法?我曾想过在将数据放入ASPxGridView之前尝试格式化数据,但我认为这同样有困难。

1 个答案:

答案 0 :(得分:0)

创建一个未绑定的列并处理gridview onCustomUnboundColumnData事件。在那种情况下,将值设置为您想要的值。

编辑:实际上,因为你只需要从数据库中舍入数字(如果你愿意放弃它的末尾)只需将列的DisplayFormat.FormatType设置为" Numeric&# 34;和DisplayFormat.FormatString显示您想要的许多小数位。

您也可以按照Here

列出的devexpress线程中的方法进行操作
相关问题