We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Can I format number as comma separated in grid?

In DataBoundDataGrid, I would like 1000 displayed as 1,000 but still treated as number type, so I can sort it properly. Is there any way to do that? Thanks a lot

3 Replies

AD Administrator Syncfusion Team April 29, 2004 11:09 AM

Try this. Make sure your DataColumn type is int so the grid thinks the column is integer. Then handle the grid.model.QueryCellFormattedText event and format the display text there.
this.gridDataBoundGrid1.Model.QueryCellFormattedText += new GridCellTextEventHandler(gridModel_QueryCellFormattedText);

//the handler
private void gridModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
	if(e.Style.CellValueType == typeof(int))
	{
		e.Text = ((int)Style.CellValue).ToString("#,###");
		e.Handled = true;
	}
}


AD Administrator Syncfusion Team April 29, 2004 12:44 PM

THanks. My grid is built based on the DB query dynamically. The fields in DB are types money and deciaml. But it seems that I can not work it out using the follwing function. ANy suggestions? Thanks for your time private void gridModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e) { if(e.Style.CellValueType == typeof(double)) { e.Text = ((double)e.Style.CellValue).ToString("#,###"); e.Handled = true; } } >Try this. Make sure your DataColumn type is int so the grid thinks the column is integer. > >Then handle the grid.model.QueryCellFormattedText event and format the display text there. > >
>this.gridDataBoundGrid1.Model.QueryCellFormattedText += new GridCellTextEventHandler(gridModel_QueryCellFormattedText);
>
>//the handler
>private void gridModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e)
>{
>	if(e.Style.CellValueType == typeof(int))
>	{
>		e.Text = ((int)Style.CellValue).ToString("#,###");
>		e.Handled = true;
>	}
>}
>


AD Administrator Syncfusion Team April 30, 2004 05:14 AM

Instead of using the type double in the code, try using the type decimal.

Loader.
Live Chat Icon For mobile
Up arrow icon