Hi Yuipcheng, David Fowler gave me the solution, which is to create a class based on the DefaultAutoFieldGenerator and override the CreateField method:
/// <summary>
/// Add the option to the Default Auto Field Generator
/// to not add the (Style="white-space: nowrap;") to each field.
/// </summary>
public class AdvancedAutoFieldGenerator : DefaultAutoFieldGenerator
{
private Boolean _noWrap;
/// <summary>
/// Initializes a new instance of the
/// <see cref="AdvancedAutoFieldGenerator"/> class.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="noWrap">if set to <c>true</c>
/// the (Style="white-space: nowrap;") is added
/// to each field.</param>
public AdvancedAutoFieldGenerator(MetaTable table, Boolean noWrap)
: base(table)
{
_noWrap = noWrap;
}
protected override DynamicField CreateField(
MetaColumn column,
ContainerType containerType,
DataBoundControlMode mode)
{
DynamicField field = base.CreateField(column, containerType, mode);
field.ItemStyle.Wrap = !_noWrap;
return field;
}
}
In the CreateFiedl method we call the base and then set the field.ItemStyle.Wrap value to turn off the nowrap feature.
I decided that I wanted to be able to turn this off or leave it on so I added a parameter to the contstuctor for this.
We use this on the List page in the Page_Load event (if we do it6 any earlier then the DefaultAutoFieldGenerator will still be applied instead) like this:
// apply custom auto field generator
GridView1.ColumnsGenerator = new AdvancedAutoFieldGenerator(table, false);
setting the noWrap parameter to false will turn off the feature wich adds the style="white-space:nowrap;" to each table cell and row.
Hope this helps [:)]
IAutoFieldGenratorDynamic Data 4DefaultAutoFieldGenerator
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Marked as answer by sjnaughton on Nov 14, 2010 10:30 AM
yuipcheng
Member
14 Points
10 Posts
Re: DynamicField within GridView truncating data
Nov 10, 2010 11:48 PM|LINK
I commented out the code to truncate the FieldValueString, but the rendered text doesn't wrap since the td tag has style="white-space: nowrap;"
There is no code to set the wrap = false anywhere.
Why is this happening?
yuipcheng
Member
14 Points
10 Posts
Re: DynamicField within GridView truncating data
Nov 10, 2010 11:58 PM|LINK
i found a workaround by adding the following css code to List.aspx, but i rather get rid of the extra style code from the td tag.
td
{
white-space:normal;
}
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: DynamicField within GridView truncating data
Nov 11, 2010 01:16 AM|LINK
Hi Yuipcheng, it would appear that DD is adding this and I can't find a way around it yet [:(]
Dynamic Data 4
Always seeking an elegant solution.
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: DynamicField within GridView truncating data
Nov 14, 2010 10:27 AM|LINK
Hi Yuipcheng, David Fowler gave me the solution, which is to create a class based on the DefaultAutoFieldGenerator and override the CreateField method:
/// <summary> /// Add the option to the Default Auto Field Generator /// to not add the (Style="white-space: nowrap;") to each field. /// </summary> public class AdvancedAutoFieldGenerator : DefaultAutoFieldGenerator { private Boolean _noWrap; /// <summary> /// Initializes a new instance of the /// <see cref="AdvancedAutoFieldGenerator"/> class. /// </summary> /// <param name="table">The table.</param> /// <param name="noWrap">if set to <c>true</c> /// the (Style="white-space: nowrap;") is added /// to each field.</param> public AdvancedAutoFieldGenerator(MetaTable table, Boolean noWrap) : base(table) { _noWrap = noWrap; } protected override DynamicField CreateField( MetaColumn column, ContainerType containerType, DataBoundControlMode mode) { DynamicField field = base.CreateField(column, containerType, mode); field.ItemStyle.Wrap = !_noWrap; return field; } }In the CreateFiedl method we call the base and then set the field.ItemStyle.Wrap value to turn off the nowrap feature.
I decided that I wanted to be able to turn this off or leave it on so I added a parameter to the contstuctor for this.
We use this on the List page in the Page_Load event (if we do it6 any earlier then the DefaultAutoFieldGenerator will still be applied instead) like this:
setting the noWrap parameter to false will turn off the feature wich adds the style="white-space:nowrap;" to each table cell and row.
Hope this helps [:)]
IAutoFieldGenrator Dynamic Data 4 DefaultAutoFieldGenerator
Always seeking an elegant solution.
yuipcheng
Member
14 Points
10 Posts
Re: DynamicField within GridView truncating data
Nov 19, 2010 12:03 AM|LINK
Steve,
that works!
Thank you!
yuipcheng