Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
I am using asp.net,c#.net 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" 
            oniteminserting="CustomerDetailView_ItemInserting">   
 
        <Fields>              
                <asp:TemplateField HeaderText="Cust Name">                
                    <ItemTemplate>
                        <asp:TextBox ID="txtPName" runat="server" Text='<%# Bind("CustomerName") %>'></asp:TextBox>
                    </ItemTemplate>                    
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Comp Name">
                    <ItemTemplate>
                        <asp:TextBox ID="txtPCName" runat="server" Text='<%# Bind("CompanyName") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>                
                <asp:TemplateField HeaderText="City">
                    <ItemTemplate>
                        <asp:TextBox ID="txtPCity" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                    </ItemTemplate>                    
                </asp:TemplateField>
                <asp:TemplateField>
                <InsertItemTemplate>
                    <asp:linkbutton id="btnPlain" runat="server" commandname="Insert" text="Save" />
                </InsertItemTemplate>            
                </asp:TemplateField>                                           
            </Fields>      
      </asp:DetailsView>         
    
        <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">
            <InsertParameters>
                <asp:Parameter Name="CustomerName" />
                <asp:Parameter Name="CompanyName" />
                <asp:Parameter Name="City" />
            </InsertParameters>
        </asp:SqlDataSource>
        
    
    </div>
    </form>
 
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
0 OriginalGriff 295
1 DamithSL 295
2 Sergey Alexandrovich Kryukov 197
3 Peter Leow 155
4 Afzaal Ahmad Zeeshan 154
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2014
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