Is it possible to change the DataFormatString of a bound column in on the Server Side in response to a button click?
I have a webdatagrid with some data in Percentages. In Edit mode, I need the column to be shows as a numeric so that the users can edit it.
How can I do this?
(PS. I used to be able to do this in the UltraWebGrid with a piece of code like this.
UltraWebGrid1.Columns(2).Format = "###,###,###.####"
I could then switch it back to a percentage like this.
UltraWebGrid1.Columns(2).Format = "###.##%"
I am finding this upgrade to WebDataGrid VERY DIFFICULT. The documentation is so imcomplete. There are barely any examples showing up when I search "DataFormatString" on the Infragistics website.
It seems like you should just be able to say something like WebDataGrid.Columns("ColumnName").DataFormatString = "#,###" or something like that.
Can someone please help?
Hello mancusor,
You can apply the needed formatting on button click like this (v http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/Infragistics4.Web.v11.2~Infragistics.Web.UI.GridControls.FormattedGridField~DataFormatString.html):
protected void Button1_Click(object sender, EventArgs e) { ((Infragistics.Web.UI.GridControls.FormattedGridField)(WebDataGrid1.Columns["Data"])).DataFormatString = "{0:N3}"; }
protected void Button1_Click(object sender, EventArgs e)
{
((Infragistics.Web.UI.GridControls.FormattedGridField)(WebDataGrid1.Columns["Data"])).DataFormatString = "{0:N3}";
}
Test this solution and let me know if it works in your scenario.
Alex,
Thanks for your reply. This snippet is in C# and I can't get it to work in VB.
FormattedGridField is not valid after GridControls
I imported Infragistics.Web.UI and Infragistics.WebUI.GridControls at the beginning of the module but that didn't help.
Hi Mancusor,
FormattedGridField was introduced as a class between GridField and BoundDataField in 11.1 to also accomodate UnboundField deriving from FormattedGridField. Bound and Unbound fields have some common properties. If you have prior to 11.1, cast it as a BoundDataField.
regards,
David Young