How to add new row to a databound gridview?

How to add an Insert row to a GridView which is databound to a SQL server table?

  • I'm using C# ASP.NET 4 (VS2010) to create a database driven aspx file (SQL SERVER 2008 R2). My aspx file containing a GridView which allows me to edit and delete rows from the SQL server's table. I would like to add an insert row at the bottom of the Gridview, but I can't find the control for that, even after searching the internet for hours. When using Microsoft SQL Server Management studio there is a way to edit the top 200 rows of a table in a nice gridview, and there is an insert row at the bottom. My GridView is pure aspx with no code behind. I would like to imitate the that insertion row. This is how the edit (with the insert row) looks on Microsoft SQL Server Management studio: See at the picture above how I'm inserting the 3rd row of the table. See that there is a new row for insertion at the bottom of the gridview. Is it possible that there is no control for that with aspx gridview? If there isn't automatic insert row control, how do I do that with minimal C# code? With no solution, I thought of adding a button at under the GridView which will add a new empty row to the table. The problem is, my table do not allow nulls :)

  • Answer:

    You'll need to make sure that you include an "InsertCommand" in your SqlDataSource and you'll need to do a little bit of work in the code-behind. To get a nice overview check out the article on this topic at the http://www.codeproject.com/Articles/18165/Using-the-Insert-feature-of-SqlDataSource-with-Gri

Different111222 at Stack Overflow Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.