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
364
Column Format settings are not working
posted

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:

int iCol = 0;

DataTable dtColumns = new DataTable();

switch (ddlQueryType.DataValue.ToString())

{

case "1":

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Header.Caption = "Company";

dtColumns = GetData.getGroupFields(ddlFields.DataValue.ToString());

break;

case "2":

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Header.Caption = "Year";

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Format = "0000.0";

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].CellStyle.HorizontalAlign = HorizontalAlign.Right;

dtColumns = GetData.getGroupFields(ddlFields.DataValue.ToString());

break;

case "3":

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Header.Caption = "Company";

dtColumns = GetData.getPeriods();break;

}

foreach (DataRow dr in dtColumns.Rows)

{

iCol++;

int iDec = Convert.ToInt32(dr["Decimals"]);

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Header.Caption = dr["Text"].ToString();

switch (dr["DataType"].ToString())

{

case "N":

String sFormat = "#,##0";

if (iDec > 0)

{

sFormat +=
".";for (int i = 1; i <= iDec; i++)

{

sFormat +=
"0";

}

}

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Format = sFormat;

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].CellStyle.HorizontalAlign =
HorizontalAlign.Right;

break;

case "Y":

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].Format = "0000.0";

ugQryResults.DisplayLayout.Bands[0].Columns[iCol].CellStyle.HorizontalAlign = HorizontalAlign.Right;

break;

case "T":break;

}

}

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:

<igtbl:UltraWebGrid ID="ugQryResults" runat="server" Height="100%" Width="100%"

OnInitializeLayout="ugQryResults_InitializeLayout"

OnDataBinding="ugQryResults_DataBinding" OnInitializeRow="ugQryResults_InitializeRow"

ImageDirectory="~/ig_res/Default/images/" TabIndex="-1">

<bands>

<igtbl:UltraGridBand>

<addnewrow view="NotSet" visible="NotSet">

</addnewrow>

</igtbl:UltraGridBand>

</bands>

<displaylayout allowcolsizingdefault="Free" bordercollapsedefault="Separate"

name="UltraWebGrid1" rowheightdefault="1px" selecttypecelldefault="Single"

selecttypecoldefault="Extended" selecttyperowdefault="Extended"

version="3.00" ColWidthDefault="-1px" GridLinesDefault="None"

IndentationDefault="0" RowSelectorsDefault="No"

allowsortingdefault="OnClient" headerclickactiondefault="SortMulti"

sortcasesensitivedefault="False" CellClickActionDefault="RowSelect"

EnableClientSideRenumbering="True" EnableInternalRowsManagement="True">

<framestyle backcolor="White" borderstyle="Solid" borderwidth="2px"

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>

<RowAlternateStyleDefault Font-Names="Microsoft Sans Serif"

Font-Size="XX-Small" BackColor="#CCCCCC" BorderColor="White"

BorderStyle="Solid" BorderWidth="0px">

<Padding Left="3px" Right="3px" />

<BorderDetails ColorLeft="White" ColorTop="White" widthleft="1px"

widthtop="1px" />

</RowAlternateStyleDefault>

<pager>

<PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">

<borderdetails colorleft="White" colortop="White" widthleft="1px"

widthtop="1px" />

</PagerStyle>

</pager>

<headerstyledefault backcolor="Silver" borderstyle="Solid" Font-Bold="True"

font-names="Microsoft Sans Serif" font-size="XX-Small" Cursor="Hand">

<borderdetails colorleft="White" colortop="White" WidthLeft="1px"

WidthTop="1px" />

</headerstyledefault>

<rowstyledefault backcolor="White" bordercolor="#CCCCCC" borderstyle="Solid"

borderwidth="0px" font-names="Microsoft Sans Serif" font-size="XX-Small"

Height="16px">

<Padding Left="3px" Right="3px" />

<borderdetails colorleft="#CCCCCC" colortop="#CCCCCC" widthleft="1px"

widthtop="1px" />

</rowstyledefault>

<SelectedRowStyleDefault BackColor="#9FBEEB">

</SelectedRowStyleDefault>

<GroupByBox Hidden="True">

</GroupByBox>

<addnewbox>

<boxstyle backcolor="LightGray" borderstyle="Solid" borderwidth="1px"

Font-Names="Microsoft Sans Serif" Font-Size="XX-Small">

<borderdetails colorleft="White" colortop="White" widthleft="1px"

widthtop="1px" />

</boxstyle>

</addnewbox>

<activationobject bordercolor="" borderwidth="0px" borderstyle="None">

</activationobject>

<AddNewRowDefault>

<RowStyle Font-Names="Microsoft Sans Serif" Font-Size="XX-Small" />

</AddNewRowDefault>

<FilterOptionsDefault AllowRowFiltering="OnClient" FilterUIType="HeaderIcons" ShowAllCondition="Yes"

ShowEmptyCondition="Yes" ShowNonEmptyCondition="Yes" FilterIcon="True"

FilterRowView="Top">

<FilterDropDownStyle BackColor="WhiteSmoke" Cursor="Default"

Font-Names="Microsoft Sans Serif" Font-Size="XX-Small">

</FilterDropDownStyle>

<FilterRowStyle Cursor="Hand" BackColor="Silver"

Font-Names="Microsoft Sans Serif" Font-Size="XX-Small">

</FilterRowStyle>

</FilterOptionsDefault>

</displaylayout>

</igtbl:UltraWebGrid>

Thanks,

Mark