Click here to Skip to main content
15,798,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using, and sql server.

I am using details-view like below design.
I want to insert values using details-view into database using Insert-mode.

Can anyone tell me the code behind how to achieve this.

Below is my Details-view aspx code.

<form id="form1"  runat="server">
    <div align="center">
     <asp:DetailsView ID="CustomerDetailView" AutoGenerateRows="False" 
            AllowPaging="True" DefaultMode="Insert" runat="server" onitemcommand="CustomerDetailView_ItemCommand" DataSourceID="SqlDataSource1" 

                <asp:TemplateField HeaderText="Cust Name">                
                        <asp:TextBox ID="txtPName" runat="server" Text='<%# Bind("CustomerName") %>'></asp:TextBox>
                <asp:TemplateField HeaderText="Comp Name">
                        <asp:TextBox ID="txtPCName" runat="server" Text='<%# Bind("CompanyName") %>'></asp:TextBox>
                <asp:TemplateField HeaderText="City">
                        <asp:TextBox ID="txtPCity" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                    <asp:linkbutton id="btnPlain" runat="server" commandname="Insert" text="Save" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
           ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" InsertCommand="INSERT INTO Customers(CustomerName, CompanyName,City) VALUES (@CustomerName,@CompanyName, @City)" SelectCommand="Select  top 1 * from Customers">
                <asp:Parameter Name="CustomerName" />
                <asp:Parameter Name="CompanyName" />
                <asp:Parameter Name="City" />

Can anyone help me how to insert data into Database after clicking SAVE button.

Thank you,

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900