Hi Simon, if the field is a long test field you may need to add a UIHint to the override the field template it is using.
I would put a break point in each of the possible field templates and then debug to see which is being used, or use F12 in IE8 to get the Dev tools and look at the column to see how it is being rendered, as this bould be a css issue (i.e. overflow set to
hidden)
Dynamic Data
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Marked as answer by dizruptor on Jun 28, 2010 11:16 AM
Thanks for pointing me in the right direction Steve. The issue was simply due to the MAX_DISPLAYLENGTH_IN_LIST constant in the default Text field template. Exactly where it should be
Now all I need is an attribute to replace this constant. Don't suppose you've got one of those up your sleeve
Thanks Steve. I jumped the gun and built one myself yesterday - my first metadata attribute. Pretty similar to yours except you also have the Row parameter which should be useful. I'll include mine here because I also implemented it in the ForeignKey field
template, which might be of interest to someone.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class MaxDisplayLengthInListAttribute : Attribute
{
public Int16 Length { get; private set; }
public MaxDisplayLengthInListAttribute(Int16 length)
{
Length = length;
}
}
Text.ascx
public override string FieldValueString
{
get
{
string value = base.FieldValueString;
if (ContainerType == ContainerType.List)
{
Int16 MaxLength = 25;
var metadata = MetadataAttributes.OfType<MaxDisplayLengthInListAttribute>().FirstOrDefault();
if (metadata != null)
{
MaxLength = metadata.Length;
}
if (value != null && value.Length > MaxLength)
{
value = value.Substring(0, MaxLength - 3) + "...";
}
}
return value;
}
}
dizruptor
Member
37 Points
112 Posts
DynamicField within GridView truncating data
Jun 28, 2010 05:06 AM|LINK
When I use a DynamicField within aGridView the data displayed in the column is truncated. How can I control this behaviour?
vishwanath_h...
Participant
968 Points
179 Posts
Re: DynamicField within GridView truncating data
Jun 28, 2010 07:43 AM|LINK
hi,
Please check datasource function you are binding the gridview, whether it is returning full data or it is getting truncated in
the function or query itself.
naveed.butt
Member
2 Points
1 Post
Re: DynamicField within GridView truncating data
Jun 28, 2010 07:45 AM|LINK
There can be multiple reasons for that to be... Is the max length property set for the text field you are using in the gridview ???
gridview truncation
dizruptor
Member
37 Points
112 Posts
Re: DynamicField within GridView truncating data
Jun 28, 2010 08:18 AM|LINK
The data isn't truncated in the source. If I use a BoundField instead of a DynamicField the data isn't truncated.
Cheers
dizruptor
Member
37 Points
112 Posts
Re: DynamicField within GridView truncating data
Jun 28, 2010 08:20 AM|LINK
The DynamicField control doesn't have a max length property.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: DynamicField within GridView truncating data
Jun 28, 2010 09:18 AM|LINK
Hi Simon, if the field is a long test field you may need to add a UIHint to the override the field template it is using.
I would put a break point in each of the possible field templates and then debug to see which is being used, or use F12 in IE8 to get the Dev tools and look at the column to see how it is being rendered, as this bould be a css issue (i.e. overflow set to hidden)
Dynamic Data
Always seeking an elegant solution.
dizruptor
Member
37 Points
112 Posts
Re: DynamicField within GridView truncating data
Jun 28, 2010 11:14 AM|LINK
Thanks for pointing me in the right direction Steve. The issue was simply due to the MAX_DISPLAYLENGTH_IN_LIST constant in the default Text field template. Exactly where it should be
Now all I need is an attribute to replace this constant. Don't suppose you've got one of those up your sleeve
Thanks, Simon
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: DynamicField within GridView truncating data
Jun 29, 2010 10:37 AM|LINK
Hi Simon, yes I do [:)]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class FieldOptionsAttribute : Attribute { /// <summary> /// Gets or sets the rows. /// </summary> /// <value>The rows.</value> public int Rows { get; set; } /// <summary> /// Gets or sets the columns. /// </summary> /// <value>The columns.</value> public int Columns { get; set; } }And then change your Test.aspx page to this.
public partial class TextField : System.Web.DynamicData.FieldTemplateUserControl { private const int MAX_DISPLAYLENGTH_IN_LIST = 25; public override string FieldValueString { get { string value = base.FieldValueString; if (ContainerType == ContainerType.List) { var fieldOptions = MetadataAttributes.OfType<FieldOptionsAttribute>().FirstOrDefault(); int maxColumns; if (fieldOptions != null && fieldOptions.Columns > 0) maxColumns = fieldOptions.Columns; else maxColumns = MAX_DISPLAYLENGTH_IN_LIST; if (value != null && value.Length > maxColumns) value = value.Substring(0, maxColumns - 3) + "..."; } return value; } } public override Control DataControl { get { return Literal1; } } }Shouls work, I also use the Row for the MultilineText_Edit field to alter how many rows it has.
Dynamic Data
Always seeking an elegant solution.
dizruptor
Member
37 Points
112 Posts
Re: DynamicField within GridView truncating data
Jun 30, 2010 01:07 AM|LINK
Thanks Steve. I jumped the gun and built one myself yesterday - my first metadata attribute. Pretty similar to yours except you also have the Row parameter which should be useful. I'll include mine here because I also implemented it in the ForeignKey field template, which might be of interest to someone.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class MaxDisplayLengthInListAttribute : Attribute { public Int16 Length { get; private set; } public MaxDisplayLengthInListAttribute(Int16 length) { Length = length; } }Text.ascx
public override string FieldValueString { get { string value = base.FieldValueString; if (ContainerType == ContainerType.List) { Int16 MaxLength = 25; var metadata = MetadataAttributes.OfType<MaxDisplayLengthInListAttribute>().FirstOrDefault(); if (metadata != null) { MaxLength = metadata.Length; } if (value != null && value.Length > MaxLength) { value = value.Substring(0, MaxLength - 3) + "..."; } } return value; } }ForeignKey.ascx
protected string GetDisplayString() { object value = FieldValue; if (value == null) { return FormatFieldValue(ForeignKeyColumn.GetForeignKeyString(Row)); } else { string stringValue = FormatFieldValue(ForeignKeyColumn.ParentTable.GetDisplayString(value)); if (ContainerType == ContainerType.List) { Int16 MaxLength = 20; var metadata = MetadataAttributes.OfType<MaxDisplayLengthInListAttribute>().FirstOrDefault(); if (metadata != null) { MaxLength = metadata.Length; } if (stringValue.Length > MaxLength) { stringValue = stringValue.Substring(0, MaxLength - 3) + "..."; } } return stringValue; } }sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: DynamicField within GridView truncating data
Jun 30, 2010 09:05 AM|LINK
Excelant job Simon, I'll certanly look at you sample [:)]
Dynamic Data
Always seeking an elegant solution.