Skip to content

Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / DataFormatString on dynamic WebDataGrid in VB.Net

DataFormatString on dynamic WebDataGrid in VB.Net

New Discussion
Rick Lanpher
Rick Lanpher asked on Jan 13, 2025 8:00 AM

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.

Sign In to post a reply

Replies

  • 0
    Zdravko Kolev
    Zdravko Kolev answered on Mar 2, 2017 3:20 PM

    Hello Rick,

    My suggestion is to use Currency editor provider for your scenario:

    http://www.infragistics.com/samples/aspnet/editors/currency-editor-localization

    Another approach that you can follow is to use format string like DisplayFormatString or on InitializeRow to change the cell value:

    https://www.infragistics.com/community/forums/f/ultimate-ui-for-asp-net/108199/for-currency-format-display-minus-symbol-for-negative-value

    • 0
      Rick Lanpher
      Rick Lanpher answered on Mar 3, 2017 3:42 PM

      I'm sorry but using a string (via FormatCurrency) inside of the datagrid will remove the Sort as well as the Sum function from the grid. The link you sent is for the WebDateTimeEditor control not for the WebDataGrid. As such I'm not sure what one has to do with the other. If there is a way to tell the WebDataGrid that a certain column should be treated as a currency value and then will sort and sum correctly please advise me of this. 

      The second example is in C# which makes it a bit difficult for me to translate, however it does seem to be using Strings again to replace the number into a correct format. Doing this again will make the WebDataGrid lose a lot of functionality. 

      I am aware that if I did not have a dynamic table I could set the format string in the HTML via 

      <ig:BoundDataField DataFieldName="BoundColumn_0" DataFormatString="${0.00}" Key="BoundColumn_0">

      How can I correctly set this field dynamically in VB.Net?

  • 0
    [Infragistics]Denis Georgiev
    [Infragistics]Denis Georgiev answered on Mar 6, 2017 12:04 PM

    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.

    • 0
      goussarova
      goussarova answered on Nov 29, 2017 9:25 PM

      Hi Denis,

      I am also having this problem.

      The link you provided results in 404 error, while the sample I downloaded does *not* show how to use FormatFieldMethod function.

      Specifically all samples from Infragistics show how to return 'hello', but do not show how to properly pass values.

      Could you please post a code sample of how to use  FormatFieldMethod function.


      Thank you,

      Helen.

  • 0
    goussarova
    goussarova answered on Dec 7, 2017 8:10 PM

    Answering my own question:,To dynamically format autogenerated field, use this:

    DirectCast(column, AutoGeneratedDataField).DataFormatString = "{0:P}"

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Rick Lanpher
Favorites
0
Replies
5
Created On
Jan 13, 2025
Last Post
8 years, 2 months ago

Suggested Discussions

Created by

Created on

Jan 13, 2025 8:00 AM

Last activity on

Feb 24, 2026 1:38 PM