Hi,
I am trying to set the columns of my WebGrid to represent the data types being displayed. I placed the following code in the grids InitializeLayout function, which determines the columns and their formats based on the type of query the user selects:
DataTable dtColumns = new DataTable();
{
ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Header.Caption = "Company";
break;
ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Header.Caption = "Year";
ugQryResults.DisplayLayout.Bands[0].Columns[iCol].CellStyle.HorizontalAlign = HorizontalAlign.Right;
}
iCol++;
ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Header.Caption = dr["Text"].ToString();
String sFormat = "#,##0";
ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Format = sFormat;
ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Format = "0000.0";
The HorizonalAlign works properly, but the Format setting doesn't seem to work, as the resulting values come out without the correct formatting (like the thousands separator or the fixed number of decimal places).
Are their any settings I need in the WebGrid to make this work? I am including my current setup for the WebGrid on this form:
OnInitializeLayout="ugQryResults_InitializeLayout"
ImageDirectory="~/ig_res/Default/images/" TabIndex="-1">
<bands>
<igtbl:UltraGridBand>
<addnewrow view="NotSet" visible="NotSet">
</addnewrow>
</igtbl:UltraGridBand>
</bands>
name="UltraWebGrid1" rowheightdefault="1px" selecttypecelldefault="Single"
version="3.00" ColWidthDefault="-1px" GridLinesDefault="None"
allowsortingdefault="OnClient" headerclickactiondefault="SortMulti"
EnableClientSideRenumbering="True" EnableInternalRowsManagement="True">
font-names="Microsoft Sans Serif" font-size="XX-Small" height="100%"
width="100%">
</framestyle>
<Images ImageDirectory="~/ig_res/Default/images/">
<CollapseImage Url="igg_sortAsc.gif" />
<FilterAppliedImage Url="ig_FilterApplied.gif" />
<FilterImage Url="ig_tblFilter.gif" />
<ExpandImage Url="igg_sortDesc.gif" />
</Images>
Font-Size="XX-Small" BackColor="#CCCCCC" BorderColor="White"
BorderStyle="Solid" BorderWidth="0px">
<Padding Left="3px" Right="3px" />
widthtop="1px" />
</RowAlternateStyleDefault>
<pager>
<PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
</PagerStyle>
</pager>
font-names="Microsoft Sans Serif" font-size="XX-Small" Cursor="Hand">
WidthTop="1px" />
</headerstyledefault>
borderwidth="0px" font-names="Microsoft Sans Serif" font-size="XX-Small"
Height="16px">
</rowstyledefault>
<SelectedRowStyleDefault BackColor="#9FBEEB">
</SelectedRowStyleDefault>
<GroupByBox Hidden="True">
</GroupByBox>
<addnewbox>
Font-Names="Microsoft Sans Serif" Font-Size="XX-Small">
</boxstyle>
</addnewbox>
<activationobject bordercolor="" borderwidth="0px" borderstyle="None">
</activationobject>
<AddNewRowDefault>
<RowStyle Font-Names="Microsoft Sans Serif" Font-Size="XX-Small" />
</AddNewRowDefault>
ShowEmptyCondition="Yes" ShowNonEmptyCondition="Yes" FilterIcon="True"
FilterRowView="Top">
</FilterDropDownStyle>
</FilterRowStyle>
</FilterOptionsDefault>
</displaylayout>
</igtbl:UltraWebGrid>
Thanks,
Mark
Hello Mark,
I am not sure that the format strings you have used are what we support in the grid. I think that for formatting values in this format, we use something like "####.#"
We typically try to follow what is used by Microsoft in the framework, e.g. what is documented here:
http://msdn.microsoft.com/en-us/library/0c899ak8(VS.71).aspx
Hi Rumen,
I have used a similar format string in a WebGrid I use in another module for this same project, and the formatting works fine there. I set a date and a numeric column to format and it works. But for this module it doesn't. The only difference is that in the one that works I bind a DataSet (results from a Select query), while in the one that doesn't work I have to fill a DataTable with the values I want to display, as i can't bind a single Select query to get all the values I need. The queries are too complex for that to work.
It's frustrating that a simple data Format works in one instance and not in an other.
Any help would be appreciated.