Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
DataFormatString on dynamic WebDataGrid in VB.Net
posted

I have a Datatable that I attach as a datasource to a Webdatagrid. The Datatable has dynamically chosen columns with dynamically chosen order. As such I never know which columns will be selected and in which order they will be. I do know the Column headers and would like to format the columns that have currency in their fields to have a $ in front of them and 2 decimals after them. I'm not able to figure out how to do this. 

For example:

WebDataGrid1.DataSource = dt

For Each col In WebDataGrid1.Columns
If col.Caption = "Total" Then

...


End If
Next

I can see 

WebDataGrid1.Columns(0).FormatFieldMethod = New FormatRecordItemValue()

But iterating through webdatagrid1 I can't find  col.FormatFieldMethod 

I can also not find what to pass to FormatRecordItemValue as it constantly tells me I'm entering the wrong value. I tried following the example in 

https://www.infragistics.com/community/forums/f/ultimate-ui-for-asp-net/19758/set-dataformatstring-in-server-side-code-for-a-specific-cell

Parents
No Data
Reply
  • 11095
    Verified Answer
    Offline posted

    Hello Rick,

    By design if the columns are auto generated, the columns collection is empty. The columns for the grid should be explicitly specified and then DataFormatString can be specified.

    I have attached sample to demonstrate this.

    FormatFieldMethod property expects a function, which has the following signature.

    [code]

    Private Function FormatFieldMethod(field As ControlDataField, value As Object) As String
        return "the formatted value"
    End Function

    [/code]

    Let me know if I may be of further assitance.

    WebDataGridFormatFieldsDynamicData.zip
Children