Can I combine an EditItemTemplate and InsertItemTemplate?

  • Thread starter Thread starter pjbates
  • Start date Start date
P

pjbates

Hi,

I've been using the GridView and DetailsView controls for a while, and
I'm beginning to get annoyed by the redundancy of EditItemTemplate and
InsertItemTemplate in many cases.

In the following code, both edit and insert templates are identical. It
would be great if I could define a generic template to be used for both
edits and inserts. I know that there are many situations where the edit
and insert templates will differ, but for the simple cases it would be
nice to use a single template.

Is there a work around for this?

Thanks

<asp:TemplateField HeaderText="EndDate" SortExpression="EndDate">
<ItemTemplate>
<asp:Label ID="Label_EndDate" runat="server"
Text='<%# Bind("EndDate") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox_EditEndDate"
runat="server" Text='<%# Bind("EndDate") %>' />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox_InsertEndDate"
runat="server" Text='<%# Bind("EndDate") %>' />
</InsertItemTemplate>
</asp:TemplateField>

Peter
 
Hey..i think i have a solution to your problem. You can nest the
Templates inside of each other like this:

<EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox id="txt" runat="server"/>
</InsertItemTemplate>
</EditItemTemplate>

I have tried this method on one page so far and have had no problems
yet. Hope this helps.
 
Back
Top