0

I have an EditItemTemplate within a ASP.NET 4.5 Web Forms FormView. I've set an ItemType on the FormView so I'm using DynamicControls to display and edit fields.

<asp:FormView runat="server" ItemType="FooModel">
    <EditItemTemplate>
        <asp:DynamicControl runat="server" ID="message" DataField="Message" Mode="Edit" />
    </EditItemTemplate>
</asp:FormView>

This seems to work ok until I set the DataType on my ItemType property to make it multiline, like so.

public class FooModel
{
    [DataType(DataType.MultilineText)]      
    public string Message { get; set; }
}

This still gives me a standard text input. Any ideas?

I could work around it by using

<asp:TextBox ID="Message" Text='<%# Bind("Message") %>' runat="server" TextMode="MultiLine" />

...but it would be nicer to just infer it from the data type on my property.

Thanks

Alexander Manekovskiy
  • 3,185
  • 1
  • 25
  • 34
James Antrobus
  • 409
  • 4
  • 16
  • Although if I work around it using an asp:textbox and Bind() then I loose my other data validation attributes which work fine, Required, StringLength etc. – James Antrobus Apr 12 '13 at 13:57

1 Answers1

0

You can manually edit dynamic data field template. Everything that you need is to make a following check in OnInit of Text_Edit.ascx control:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    if(Column.DataTypeAttribute.DataType == DataType.MultilineText)
        TextBox1.TextMode =  TextBoxMode.MultiLine;
}

Column property of FieldTemplateUserControl gives you all the information about the model property metadata.

Alexander Manekovskiy
  • 3,185
  • 1
  • 25
  • 34
  • Should I have the DynamicData\FieldTemplate directory in my project already or do I need to add this and create the controls as necessary? I have an upgraded project rather than a new 4.5 project. – James Antrobus Apr 15 '13 at 08:36
  • @JamesAntrobus I think you should have `DynamicData\FieldTemlates` folder in your project. Either copy it from new Dynamic Data project template or use NuGet package http://nuget.org/packages/DynamicDataTemplatesCS/. – Alexander Manekovskiy Apr 15 '13 at 10:44