Click here to Skip to main content
13,298,731 members (47,489 online)
Rate this:
Please Sign up or sign in to vote.
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,
Posted 13-Jul-12 2:05am

1 solution

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100