I am reading ASP.NET 3.5 Dummies book. I am on Chapter 4 and learning FormsView. The FormsView new button is not firing InsertItemTemplate. I have no idea where I am wrong in the below code. According to the book it should work without code-behind added

Please help me figure out where I am wrong in the aspx code.

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="ID" DataSourceID="SqlDataSource1" 
            EmptyDataText="There are no data records to display." AllowSorting="True" 
            CellPadding="4" ForeColor="#333333" GridLines="None" 
            >
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" 
                    SortExpression="ID" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
                <asp:BoundField DataField="DateAdded" HeaderText="Date Added" 
                    SortExpression="DateAdded" ApplyFormatInEditMode="True" 
                    DataFormatString="{0:MMM d,yyyy}" HtmlEncode="False" />
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>
        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID">
            <InsertItemTemplate>
                Title:
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>' ></asp:TextBox>
                <br />
                <br />
                Description:
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                <br />
                <br />
                Date Added:
                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("DateAdded") %>'></asp:TextBox>
                <br />
                <br />
                <asp:LinkButton ID="LinkButton2" runat="server">Insert</asp:LinkButton>
                 <asp:LinkButton ID="LinkButton3" runat="server">Cancel</asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server">New</asp:LinkButton>
            </ItemTemplate>
        </asp:FormView>
        <br />




        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:JulieDVDConnectionString1 %>" 
            DeleteCommand="DELETE FROM [Movies] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [Movies] ([Title], [Description], [DateAdded]) VALUES (@Title, @Description, @DateAdded)" 
            ProviderName="<%$ ConnectionStrings:JulieDVDConnectionString1.ProviderName %>" 
            SelectCommand="SELECT [ID], [Title], [Description], [DateAdded] FROM [Movies]" 

            UpdateCommand="UPDATE [Movies] SET [Title] = @Title, [Description] = @Description, [DateAdded] = @DateAdded WHERE [ID] = @ID" >
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="DateAdded" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="DateAdded" Type="DateTime" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>

    </div>
    </form>
</body>
</html>

Thanks in advance!

Try adding CommandName="Insert" to the link button in the item template

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.