Apply custom UI (FieldTemplate) to a details view TEMPALTE field RRS feed

  • Question

  • User-484343887 posted

    I changed one of my fields from <asp:DynamicField....to a <asp:TemplateField...and I lost my custom UI behavior defined for that specific field type. Is there a way to make it still happen?



    Tuesday, October 21, 2008 1:47 PM

All replies

  • User-330204900 posted

    Yes inside your templated field you will need to add the <asp:DynamicControl this is the control that is created inside the DynamicField.

    Hope this helps [:D]

    Tuesday, October 21, 2008 3:16 PM
  • User-484343887 posted

    Great..that helped. One more thing...

    Now that I have  a dynamicControl, how can I extract the (.Text) property if it is rendered a textbox? I am doing some processing on the DetailView DataBound event.




    Tuesday, October 21, 2008 6:40 PM
  • User-330204900 posted

    Hi have a look at this post: Find dynamic control

    where David suggests this way of accessing you field:

    var ftuc = (FieldTemplateUserControl)DetailsView1.FindFieldTemplate("YourFieldName");
    var dataControl = (TextBox)ftuc.DataControl;
    // Do the same of the other fields you care about, and hook them up as you need

    Wednesday, October 22, 2008 3:15 AM
  • User-484343887 posted

    it is not working. I am using the ID property of my dynamic control as the "YourFieldName". Is that wrong? If so, what is the "YourFieldName". Here is my html...

    <asp:TemplateField HeaderText="Project No.">


                     <%--<asp:TextBox ID="txtProjectNo" runat="server" Text='<%# Bind("ProjectNo") %>'></asp:TextBox>--%>

                    <asp:DynamicControl ID="txtProjectNo" DataField="ProjectNo" runat="server" Mode="Insert">




                    <asp:DynamicControl ID="dynProjectNo" DataField="ProjectNo" runat="server" Mode="Edit">




    Wednesday, October 22, 2008 3:19 PM
  • User1024101778 posted

    Try using:


    Wednesday, October 22, 2008 3:41 PM
  • User-484343887 posted

    Yes, that did it. Thanks a lot

    Wednesday, October 22, 2008 4:01 PM