Is it possible to customize the auto-generated FormView templates?
I'm not a complete idiot (just a partial one ;)) so before you go "duh, just go to the markup source and have at it" please read on.
Using Visual Studio 2005, when you drop a DataSource on the page, then a subsequent FormView, and then select the said DataSource on the FormView designer it immediately drops a bunch of a ASP.NET markup for item, edit, and insert templates. This is what I want to customize. I have many tables so hand editing is not what I'm looking to do. I would like to figure out how to get it to generate slightly different markup. Namely I want custom labels next to the controls (Labels for the ItemTemplate and TextBoxes for the Edit and Insert).
To better demonstrate, as soon as you select a DataSource you get something like the follow.
Code:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="CustNo,NoteType" DataSourceID="CustInfoSource">
<ItemTemplate>
CustNo:<asp:Label ID="CustNoLabel" runat="server" Text='<%# Eval("CustNo") %>'></asp:Label><br />
NoteType:<asp:Label ID="NoteTypeLabel" runat="server" Text='<%# Bind("NoteType") %>'></asp:Label><br />
Notes:<asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New"></asp:LinkButton>
</ItemTemplate>
[... Edit and InsertTemplate left out for space ...]
</asp:FormView>
That's all swell and fantastic but I would prefer it spit out something like the following.
Code:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="CustNo,NoteType" DataSourceID="CustInfoSource">
<ItemTemplate>
<span>Customer No</span>:<asp:Label ID="CustNoLabel" runat="server" Text='<%# Eval("CustNo") %>'></asp:Label><br />
<span>Note Type</span>:<asp:Label ID="NoteTypeLabel" runat="server" Text='<%# Bind("NoteType") %>'></asp:Label><br />
<span>Notes</span>:<asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New"></asp:LinkButton>
</ItemTemplate>
[[... Edit and InsertTemplate left out for space ...]]
</asp:FormView>
I made bold the main bits that would like to be able to customize. This isn't all I would like in the end but if I can fix this as a start I would be really happy. I would like it to output nice names for the corresponding controls' label. Now these names I have in a multitude of places, two of which are the Caption property of the associated columns in the strongly typed DataTables and a database that maps table columns to nice descriptive names. I find it kind of odd that the FormView doesn't automatically use the Caption property to generate labels but that's another issue.
So, can anyone help me? I am crossing my fingers hoping that someone is going to come and tell me how stupid I am all I have to do is X. Please make me a fool! Thank you.