Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Insert on DataGridView is not working on my ASP.Net web page

Avatar of dyarosh
dyarosh asked on
ASP.NET
5 Comments1 Solution432 ViewsLast Modified:
I have the following definition in a form on my webpage.  The code puts a datagridview on the page and populates the grid from a table in my database.  Each row has an Edit, Delete option.  If Edit is chosen, the user can change the fields in the datagridview.  When finished with the modifications, the Update option is clicked at which time the changes are made to the database.  This works as I expected and want.  The last row in the datagridview is to insert a new record.  When I try and do the Insert, a new record is added but the fields are blank.  I copied this format from another page that does the same thing with a different table and that jpage works fine.  I'm probably just missing something but can't figure out what it is.  Any help would be greatly appreciated.
<asp:GridView ID="BereavementFacilitatorsGridView" runat="server" DataSourceID="BereavementFacilitators" 
                    AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" 
                    ShowFooter="True" EmptyDataText="No Facilitators Found">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                            ReadOnly="True" SortExpression="ID" Visible="False" />
                        <asp:BoundField DataField="Category" HeaderText="Category" 
                            SortExpression="Category" Visible="False" />
                        <asp:TemplateField HeaderText="Contact" SortExpression="Contact">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Contact") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="NewFacilitatorTB" runat="server" Width="218px"></asp:TextBox>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Contact") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Phone" SortExpression="Phone">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="NewFacilitatorPhoneTB" runat="server" Width="218px"></asp:TextBox>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <EditItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                                    CommandName="Update" Text="Update"></asp:LinkButton>
                                &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                    CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                    CommandName="Edit" Text="Edit"></asp:LinkButton>
                                &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                    CommandName="Delete" Text="Delete"></asp:LinkButton>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:Button ID="AddNewFacilitator" runat="server" CausesValidation="false"
                                    CommandName="Insert" Text="Insert" OnClick="AddNewFacilitator_Click"></asp:Button>
                            </FooterTemplate>    
                         </asp:TemplateField>
                    </Columns>
                    </asp:GridView>
                <asp:AccessDataSource ID="BereavementFacilitators" runat="server" 
                    DataFile="~/App_Data/ABVM.mdb" 
                    SelectCommand="SELECT [ID], [Category], [Contact], [Phone] FROM [Bereavement] WHERE ([Category] = ?)"
                    DeleteCommand="DELETE FROM [Bereavement] WHERE [ID] = ?" 
                    InsertCommand="INSERT INTO [Bereavement] ([Category], [Contact], [Phone]) VALUES (?, ?, ?)" 
                    UpdateCommand="UPDATE [Bereavement] SET [Contact] = ?, [Phone] = ? WHERE [ID] = ?">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="Facilitators" Name="Category" Type="String" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="ID" Type="Int32" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Contact" Type="String" />
                        <asp:Parameter Name="Phone" Type="String" />
                        <asp:Parameter Name="ID" Type="Int32" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter DefaultValue="Facilitators" Name="Category" Type="String" />
                        <asp:Parameter Name="Contact" Type="String" />
                        <asp:Parameter Name="Phone" Type="String" />
                    </InsertParameters>
               </asp:AccessDataSource>
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir RivkinFlag of Israel imageFull stack Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers