Uncategorized

Infragistics UltraWebGrid column format not being applied


Just a short post today, recalling an incident I came across recently, which I thought I should jot down here, and hopefully It’ll save someone else a headache.

If you have been working with the 3rd party UltraWebGrid control for asp.net offered by Infragistics, you would have worked with columns where you might have wanted to display numerical values formatted in a certain way (for example, you may want to show 12, 300, 450.0 instead of 12300450.0000). This is done by setting the format expression in the column.Format property inside the ‘InitializeLayout()’ UltraWebGrid method. This is exactly what I was doing but was puzzled to have rows of integers merged from two DataTable sources showing different formats, even though each Integer in the rows were applied the same column.Format expression in code. The first few integers would display in the correct format I apply, but sometimes the last few integers don’t have the formatting applied.

This was getting way too frustrating till I (out of curiosity, and nothing else to try) wrote the following line of code before the ‘column.Format’ expression:

string dType = column.DataType;

When I debugged the code, one set of integers from the original DataTable was of type ‘System.Decimal’, and displayed correctly, but the second set of merged integers from the second DataTable was of type ‘System.String’. When I set the following line of code inside the loop applying the formatting to the column.Format property, all the integers displayed in the correct format:

column.DataType = “System.Decimal”;

So bottom line? The UltraWebGrid control cannot format columns with decimal format expressions if even one value in the column is going to be of a type other than ‘System.Decimal’. If there are several columns which will display numerical data in a certain format that you need, it would be defensive coding to write the logic in UltraWebGrid_InitializeLayout() as follows:

foreach (<column in UltraWebGrid that is going to display numeric values>) {

column.DataType = “System.Decimal”;

column.Format = <your numeric format expression here>;

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s