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 new record - asp:GridView

Avatar of websss
websssFlag for Kenya asked on
ASP.NET
5 Comments1 Solution243 ViewsLast Modified:
Hi

I've put a grid view on a page and its automaticallly added the facility to update and delete the record, however, the insert new record doesn't seem to work

below is the code, can anyone fix this for me please (i can replicate it then through other tables that need updating - with more feilds)

thanks


<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:myConnectionString %>" 
            SelectCommand="SELECT [ID], [LocationName] FROM [Locations]" 
            ConflictDetection="CompareAllValues" 
            DeleteCommand="DELETE FROM [Locations] WHERE [ID] = @original_ID AND (([LocationName] = @original_LocationName) OR ([LocationName] IS NULL AND @original_LocationName IS NULL))" 
            InsertCommand="INSERT INTO [Locations] ([LocationName]) VALUES (@LocationName)" 
            OldValuesParameterFormatString="original_{0}" 
            UpdateCommand="UPDATE [Locations] SET [LocationName] = @LocationName WHERE [ID] = @original_ID AND (([LocationName] = @original_LocationName) OR ([LocationName] IS NULL AND @original_LocationName IS NULL))">
            <DeleteParameters>
                <asp:Parameter Name="original_ID" Type="Int32" />
                <asp:Parameter Name="original_LocationName" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="LocationName" Type="String" />
                <asp:Parameter Name="original_ID" Type="Int32" />
                <asp:Parameter Name="original_LocationName" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="LocationName" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
            DataKeyNames="ID" DataSourceID="SqlDataSource1" ForeColor="#333333" 
            GridLines="None">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:CommandField ShowEditButton="True" ShowDeleteButton="true" />
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="LocationName" HeaderText="LocationName" 
                    SortExpression="LocationName" />
                    <asp:CommandField ShowInsertButton="true" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            
        </asp:GridView>
ASKER CERTIFIED SOLUTION
Avatar of NazoUK
NazoUKFlag of United Kingdom of Great Britain and Northern Ireland image

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