Solved

InsertItemTemplate question

Posted on 2011-03-01
2
307 Views
Last Modified: 2012-05-11
I have the following code in an ASP page.   I'm just trying to get a very basic 2 field insert done, but when the page is rendered, none of the fields in the formview even show up on the page (nor in the source code).   What am I doing wrong here?
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:KartrisSQLConnection %>" 

                InsertCommand="INSERT INTO [tblDCPersonTest] ([pers_firstname], [pers_middlename], [pers_lastname], [pers_ssn], [pers_dob], [pers_phonehome], [pers_phonework], [pers_personid]) VALUES (@pers_firstname, @pers_middlename, @pers_lastname, @pers_ssn, @pers_dob, @pers_phonehome, @pers_phonework, @pers_personid)" 
>

                <InsertParameters>
                    <asp:Parameter Name="pers_firstname" Type="String" />
                    <asp:Parameter Name="pers_middlename" Type="String" />
                    <asp:Parameter Name="pers_lastname" Type="String" />
                    <asp:Parameter Name="pers_ssn" Type="String" />
                    <asp:Parameter Name="pers_dob" Type="String" />
                    <asp:Parameter Name="pers_phonehome" Type="String" />
                    <asp:Parameter Name="pers_phonework" Type="String" />
                    <asp:Parameter Name="pers_personid" Type="Object" />
                </InsertParameters>
            </asp:SqlDataSource>

                        <asp:FormView ID="FormView1" runat="server" DataSourceId="SqlDataSource1" DataKeyNames="pers_personid">
                            <InsertItemTemplate> 
                            First Name: <asp:TextBox ID="pers_firstname" runat="server" Text='<%# Bind("pers_firstname") %>'></asp:TextBox><br />
                            Last Name: <asp:TextBox ID="pers_lastname" runat="server" Text='<%# Bind("pers_lastname") %>'></asp:TextBox><br />
                            <asp:Button ID="butSubmit" runat="server" CommandName="Insert" Text="Submit" />
                            </InsertItemTemplate>
                        </asp:FormView>

Open in new window

0
Comment
Question by:saturation
2 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
Comment Utility
For an insertitemtemplate to be shown the formview has to be in insert mode by default it will show only an ItemTemplate to change this add a DefaultMode attribute to the formview tag and set to INsert :

<asp:FormView ID="FormView1" runat="server" DataSourceId="SqlDataSource1" DataKeyNames="pers_personid" DefaultMode="Insert">
0
 

Author Closing Comment

by:saturation
Comment Utility
Great!  Now I have a follow-up question about the InsertCommand and my primary key field.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now