简体   繁体   English

如何在 Infragistics WebDataGrid 中为动态添加的列设置格式?

[英]How do I set formatting for a dynamically added column in Infragistics WebDataGrid?

I'm currently working with a utility that was written using the Infragistics WebDataGrid control.我目前正在使用使用 Infragistics WebDataGrid 控件编写的实用程序。 The tool allows a user to select a table from a drop-down list at which point it runs a stored procedure to get data from SQL Server which it then binds to the grid.该工具允许用户从下拉列表中选择一个表,然后运行存储过程从 SQL Server 获取数据,然后将其绑定到网格。

Everything gets a default format, which for datetime columns is simply MM/DD/YYYY in this case.一切都有一个默认格式,在这种情况下,日期时间列只是MM/DD/YYYY There is a request to include the time component for at least one of these columns.请求包含至少这些列中的一列的时间分量。

After much searching I've tried to add code to the _InitializeRow event handler for the grid, but I can't seem to get it quite right.经过多次搜索,我尝试将代码添加到网格的_InitializeRow事件处理程序中,但我似乎无法完全正确。 Here's what I've come up with:这是我想出的:

if (e.Row.Index == 0)
{
    foreach (GridRecordItem field in e.Row.Items)
    {
        if (field.Column.Key == "InsertedOnCC")
            field.Column.FormatValue = "{0:g}";
    }
}

This gives me an error that FormatValue cannot have a value assigned because it is a method group.这给了我一个错误,即FormatValue不能分配值,因为它是一个方法组。

This was pieced together from several sources, none of which did quite what I wanted to do.这是从几个来源拼凑起来的,没有一个能完全达到我想要的效果。 For example, one piece of sample code just always assumed that the column in question was the first column, so I had to add the foreach loop.例如,一段示例代码总是假设有问题的列是第一列,所以我不得不添加foreach循环。

I've seen a lot of mention of BoundDataField and DataFormatString , but I can't seem to actually find how to access those.我已经看到很多人提到BoundDataFieldDataFormatString ,但我似乎无法真正找到如何访问它们。

NOTE: I'm actually a SQL Developer, not a C# developer, so please be gentle.注意:我实际上是一名 SQL 开发人员,而不是 C# 开发人员,所以请保持温和。 :) :)

Thanks!谢谢!

I was able to sort this out by casting the Column as a BoundDataField then using the DataFormatString from there: 我能够通过将ColumnBoundDataField然后从那里使用DataFormatString来解决此问题:

        if (e.Row.Index == 0)
        {
            foreach (GridRecordItem gri in e.Row.Items)
            {
                BoundDataField field = gri.Column as BoundDataField;

                if (field.Key == "InsertedOnCC")
                    field.DataFormatString = "{0:g}";
            }
        }

using the info above i was able to get this to work.使用上面的信息,我能够让它工作。 cleaner.清洁工。 does not require the loop:不需要循环:

TryCast(.Rows(0).Items.FindItemByKey("MyColumnName").Column, Infragistics.Web.UI.GridControls.BoundDataField).DataFormatString = "{0:G}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Infragistics WebDataGrid复选框和隐藏列问题 - Infragistics WebDataGrid Checkbox and hidden column problems Infragistics:如何动态添加数据并使用ForceDirectedGraphDiagramLayout? - Infragistics: How do I Dynamically add data and use ForceDirectedGraphDiagramLayout? 在WebDataGrid中获取Infragistics中多列标题的标题行计数 - Getting the Header Rows Count of Multi Column Header in WebDataGrid, Infragistics 将onClick添加到Infragistics WebDataGrid - Add an onClick to an Infragistics WebDataGrid 如何使用Infragistics设置Office 2007样式? - How do I set the office 2007 style with Infragistics? Infragistics WebDataGrid通过列名称从选定的行获取值:VB.net到C#的转换 - Infragistics WebDataGrid get value from a selected row by column name: VB.net to C# conversion 什么是使用Infragistics WebDataGrid和SQL Server 2008进行分页的理想方式 - What would be the ideal way to do paging using a Infragistics WebDataGrid and SQL Server 2008 如何将绑定到集合类的列呈现为Infragistics UltraWinGrid中的子行? - How do I render a column bound to a collection class as a child row in an Infragistics UltraWinGrid? 将工具提示分配给Infragistics WebDataGrid中所选行的单元格 - Assign Tooltip to cell of selected row in Infragistics WebDataGrid 在infragistics datagrid中设置列标题 - Set column title in infragistics datagrid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM