We help IT Professionals succeed at work.

How to insert data from the gridview in to the database?

tryokane
tryokane asked
on
I have represented data into gridview's one column,into another column i put a textbox for accepting user's data in each row.Now i want to input all data from both columns in to the database.Can u tell me how to do.Code is appreciated?
<asp:GridView ID="GridView1" runat="server"  Style="z-index: 102; left: 22px; position: absolute;top: 21px" Width="407px" AutoGenerateColumns="false" Height="176px" OnRowCommand="GridView1_RowCommand" >
           <Columns>
         <asp:TemplateField>
            <ItemTemplate>
               <asp:DropDownList ID="ddlOrder" runat="server">
                        <asp:ListItem>View</asp:ListItem>
                        <asp:ListItem>Delete</asp:ListItem>
                        <asp:ListItem>Both</asp:ListItem>
                         </asp:DropDownList>&nbsp;
                          </ItemTemplate>
           </asp:TemplateField>
            <asp:BoundField DataField="controlvalue" HeaderText="FormFillerIds" >
              <ItemStyle BackColor="White" />
          </asp:BoundField>
                 <asp:TemplateField>
                 <ItemTemplate>
                  
                  <asp:Button ID="Button1" runat="server" Text="Insert" OnClick="Button1_Click" Width="70px" Height="30px" />
            
                 </ItemTemplate>
                 </asp:TemplateField>
         </Columns>
              
        </asp:GridView>

Open in new window

Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Check if this is enough for you http://forums.asp.net/p/1210560/2131957.aspx

Author

Commented:
Can we insert the data in the gridview row command.How to do?
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Yes, using the edit, update and delete but add i don't know ... Normally the gridview is bind to some datasource and you add data to the data source and then refresh the gridview.

Can you explain better what you want ?

Check this video helps http://www.asp.net/learn/videos/video-07.aspx
Or this link (it has very good starting manuals) http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/gridview.aspx

Author

Commented:
what i want is i want to insert the data from each row in to database.I am placing an insert button in each row.I want to insert each row in to the database on clicking the button.Can we use gridview row command for this insertion.If so can u tell me how?
IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
Not in the gridview. Is't not like winforms datagridview that you can add, change, delete, update.

You can use a DetailsView to do that. Check in this link in the end (last two example) http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/detailsview.aspx

Again the easy way is to add some textboxes and a button to insert and after the insert just bind the gridview for refresh the itens.

Author

Commented:
Thanks for ur response.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.