Click here to Skip to main content
16,014,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello sir.
i want to insert data from details view to database.
i took a detailsview control and some textboxes, and one button. then how can i save the data to database.
my code is below.
if anybody know plz helpme.

XML
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
                        DataKeyNames="ProductID" AllowPaging="False" Width="500"
                        EnableViewState="False">
                        <AlternatingRowStyle BackColor="White" />
                        <headerstyle backcolor="Navy" forecolor="White"/>

                        <Fields>

                            <asp:TemplateField HeaderText ="Category-id">
                                <InsertItemTemplate >

                                </InsertItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtCategoryid" runat="server"></asp:TextBox>
                                    <asp:Label ID="LabelCategoryid" runat="server" ></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText ="Category-description">
                                <InsertItemTemplate >

                                </InsertItemTemplate>
                                <EditItemTemplate>

                                    <asp:Label ID="LabelCategoryid" runat="server" ></asp:Label>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtCategorydescription" runat="server"></asp:TextBox>
                                    <asp:Label ID="LabelCategorydescription" runat="server" ></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText ="Additional field 1">
                                <InsertItemTemplate >

                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtAdditionalfield1" runat="server" ></asp:TextBox>
                                    <asp:Label ID="LblAdditionalfield1" runat="server" ></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText ="Additional field 2">
                                <ItemTemplate >
                                    <asp:TextBox ID="TxtAdditionalfield2" runat="server"></asp:TextBox>
                                    <asp:Label ID="LblAdditionalfield2" runat="server" ></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText ="Additional field 3">
                                <ItemTemplate >
                                    <asp:TextBox ID="TxtAdditionalfield3" runat="server"></asp:TextBox>
                                    <asp:Label ID="LblAdditionalfield3" runat="server" ></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText ="Additional field 4">
                                <ItemTemplate >
                                    <asp:TextBox ID="TxtAdditionalfield4" runat="server"></asp:TextBox>
                                    <asp:Label ID="LblAdditionalfield4" runat="server" ></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField >
                                <ItemTemplate>
                                    <asp:Button ID="BtnSave" Text ="Save" runat="server" Width="80"/>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Fields>
                    </asp:DetailsView>
Posted

Lots of examples here on how to use a DetailsView:

Google search - detailsview example[^]
 
Share this answer
 
Have a look at the following article.

GridView-DetailsView (Master/Detail) Control[^]

Also this one too. GridView extras - DetailsView[^]
 
Share this answer
 
v2

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