![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
From: "TS" <manofsteele1 (AT) nospam (DOT) nospam Subject: DataFormatString not getting applied to GridView's BoundField Date: Tue, 18 Dec 2007 09:48:00 -0600 Hello, I have a control that inherits from GridView and i'm overriding databinding. My control works correctly but is not respecting the DataFormatString property that i'm setting on the field. As you will notice, i am using column information from meta data. The actual format string from meta data is "{0:d}" and the field type is a dateTime show it should show a short date. Why isn't this one property formatting correctly? thanks protected override void OnDataBinding(EventArgs e){ IList list = Utils.Utils.GetDomainObjectList(DomainObjectListKe y); bool gridViewHasDataRows = (list != null && list.Count > 0); CreateColumns(gridViewHasDataRows); if (DataSource == null) DataSource = list; base.OnDataBinding(e); } protected void CreateColumns(bool gridViewHasDataRows) { if (MetaData == null) MetaData = GridViewMetaData.GetGridViewMetaData(MetaDataId); DataControlField dcf = new BoundField(); Columns.Clear(); foreach (GridViewColumnMetaData columnMetaData in MetaData.Columns) { ((BoundField)dcf).DataField = columnMetaData.PropertyName; ((BoundField)dcf).DataFormatString = columnMetaData.DataFormatString; //Here is the line that I am setting it dcf.HeaderText = columnMetaData.HeaderText; if (columnMetaData.IsSortable) dcf.SortExpression = columnMetaData.SortPropertyName; dcf.Visible = columnMetaData.IsDisplayed; dcf.ItemStyle.HorizontalAlign = columnMetaData.HorizontalAlign; dcf.ItemStyle.Width = columnMetaData.Width; Columns.Add(dcf); } } |
#3
| |||
| |||
|
|
Hi TS, From your description, I understand you've created a custom GridView class derived from built-in one. And in its code you programmatically populate all the columns through some info in metadata. However, you found the boundfield(which has DataFormatString set) does not format output as expected, correcct? Based on my experience, ASP.NET GridView control has a common issue about DataformatString. That is the "HtmlEncode" setting for BoundField. By deafult it is turn on which will cause the "DataFormatString" not applied. You will need to turn it off so as to make DataFormatString applied. Here is a blog article also mentioned this: #BoundField DataFormatString attribute not being applied. http://weblogs.asp.net/rajbk/archive...31/429090.aspx You can try it to see whether it helps. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- From: "TS" <manofsteele1 (AT) nospam (DOT) nospam Subject: DataFormatString not getting applied to GridView's BoundField Date: Tue, 18 Dec 2007 09:48:00 -0600 Hello, I have a control that inherits from GridView and i'm overriding databinding. My control works correctly but is not respecting the DataFormatString property that i'm setting on the field. As you will notice, i am using column information from meta data. The actual format string from meta data is "{0:d}" and the field type is a dateTime show it should show a short date. Why isn't this one property formatting correctly? thanks protected override void OnDataBinding(EventArgs e){ IList list = Utils.Utils.GetDomainObjectList(DomainObjectListKe y); bool gridViewHasDataRows = (list != null && list.Count > 0); CreateColumns(gridViewHasDataRows); if (DataSource == null) DataSource = list; base.OnDataBinding(e); } protected void CreateColumns(bool gridViewHasDataRows) { if (MetaData == null) MetaData = GridViewMetaData.GetGridViewMetaData(MetaDataId); DataControlField dcf = new BoundField(); Columns.Clear(); foreach (GridViewColumnMetaData columnMetaData in MetaData.Columns) { ((BoundField)dcf).DataField = columnMetaData.PropertyName; ((BoundField)dcf).DataFormatString = columnMetaData.DataFormatString; //Here is the line that I am setting it dcf.HeaderText = columnMetaData.HeaderText; if (columnMetaData.IsSortable) dcf.SortExpression = columnMetaData.SortPropertyName; dcf.Visible = columnMetaData.IsDisplayed; dcf.ItemStyle.HorizontalAlign = columnMetaData.HorizontalAlign; dcf.ItemStyle.Width = columnMetaData.Width; Columns.Add(dcf); } } |
#4
| |||
| |||
|
|
thanks steven that was it. "Steven Cheng[MSFT]" <stch... (AT) online (DOT) microsoft.com> wrote in message news:YVuUKTfQIHA.4200 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl... Hi TS, From your description, I understand you've created a custom GridView class derived from built-in one. And in its code you programmatically populate all the columns through some info in metadata. However, you found the boundfield(which has DataFormatString set) does not format output as expected, correcct? Based on my experience, ASP.NET GridView control has a common issue about DataformatString. That is the "HtmlEncode" setting for BoundField. By deafult it is turn on which will cause the "DataFormatString" not applied. You will need to turn it off so as to make DataFormatString applied. Here is a blog article also mentioned this: #BoundField DataFormatString attribute not being applied. http://weblogs.asp.net/rajbk/archive...31/429090.aspx You can try it to see whether it helps. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ps/default.asp... ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- From: "TS" <manofstee... (AT) nospam (DOT) nospam Subject: DataFormatString not getting applied to GridView's BoundField Date: Tue, 18 Dec 2007 09:48:00 -0600 Hello, I have a control that inherits from GridView and i'm overriding databinding. My control works correctly but is not respecting the DataFormatString property that i'm setting on the field. As you will notice, i am using column information from meta data. The actual format string from meta data is "{0:d}" and the field type is a dateTime show it should show a short date. Why isn't this one property formatting correctly? thanks protected override void OnDataBinding(EventArgs e){ IList list = Utils.Utils.GetDomainObjectList(DomainObjectListKe y); bool gridViewHasDataRows = (list != null && list.Count > 0); CreateColumns(gridViewHasDataRows); if (DataSource == null) DataSource = list; base.OnDataBinding(e); } protected void CreateColumns(bool gridViewHasDataRows) { if (MetaData == null) * *MetaData = GridViewMetaData.GetGridViewMetaData(MetaDataId); DataControlField dcf = new BoundField(); Columns.Clear(); foreach (GridViewColumnMetaData columnMetaData in MetaData.Columns) { ((BoundField)dcf).DataField = columnMetaData.PropertyName; ((BoundField)dcf).DataFormatString = columnMetaData.DataFormatString; //Here is the line that I am setting it dcf.HeaderText = columnMetaData.HeaderText; if (columnMetaData.IsSortable) *dcf.SortExpression = columnMetaData.SortPropertyName; dcf.Visible = columnMetaData.IsDisplayed; dcf.ItemStyle.HorizontalAlign = columnMetaData.HorizontalAlign; dcf.ItemStyle.Width = columnMetaData.Width; Columns.Add(dcf); } }- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |