Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2007, 09:49 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Customize autogenerated FormView templates?

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.
 
Old March 12th, 2007, 10:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. as far as I see.. you will have to edit every label... Who better know what you want to write than you??

the other thing you can do is: if the text is always the same, use a macro to do a search and replace in the aspx files...




HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old March 12th, 2007, 11:19 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I said I would like it to at the very least use the DataColumn's Caption property as the label instead of the ColumnName, so I don't think it would be as difficult as guessing what I want it to write for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
entring autogenerated value to data base vaibhav_sapre C# 0 March 13th, 2007 01:51 PM
Validation controls and FormView templates bpdsmark BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 September 28th, 2006 08:56 AM
Autogenerate Formview templates wirerider ASP.NET 2.0 Basics 3 August 1st, 2006 06:55 PM
how to email the autogenerated employeeid debjanib ASP.NET 1.0 and 1.1 Professional 7 July 27th, 2006 06:38 AM
Autogenerated id in SQL Server 2000 evelynlsy SQL Server 2000 3 April 3rd, 2005 03:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.