There are two methods Using sql commands with text boxes and so but you have to do some coding to data ding these inset text boxes. So if you don’t like to do much coding here is a short cut.
The GridView control provides a template called Empty Data Template. This template is displayed when there is no data to be displayed in the GridView. Normally this template is used to display a status message to the end user that there is no data to be displayed. However, you can use this template for any other purpose also. In this example you will use it to add a new record to the GridView.
Creating a Sample Web Form
Begin by creating a new web site in Visual Studio. Drag and drop an SQL Data Source control and configure it to select CustomerID, CompanyName, ContactName and Country columns from Customers table of Northwind database.
Make sure to choose Advanced button and select "Generate INSERT, UPDATE and DELETE" statements checkbox.
Now add a GridView control to the web form and set its DataSourceID property to SqlDataSource1. Also enable editing, deleting and paging for the grid. From the smart tag of the GridView select "Edit columns..." option.
Add a ButtonField to the grid and set its CommandName property to Insert. Users will click on Insert button to insert a new record.
Now right click on the GridView and choose Edit Template - Empty Data Template menu option. Drag and drop a DetailsView control inside Empty Data Template and set its DataSourceID property to SqlDataSource1.
Also set its DefaultMode property to Insert. This way when the Empty Data Template is displayed the DetailsView will be ready for insertion.
Now go in the code behind of the web form and write RowCommand event handler of GridView as shown below:
protected void GridView1_RowCommand
(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
GridView1.DataSourceID = "";
GridView1.DataBind();
}
}Here we check if the CommandName of GridViewCommandEventArgs class is Insert. If so we set DataSourceID property of GridView to empty string and call DataBind() method of GridView. This way the grid will not have any data and Empty Data Template will be displayed.
Now handle ItemInserted event of DetailsView control. The ItemInserted event is raised when DetailsView inserts a new record successfully. Write the following code inside the ItemInserted event handler:
protected void DetailsView1_ItemInserted
(object sender, DetailsViewInsertedEventArgs e)
{
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
}Here we set DataSourceID property of GridView again to SqlDataSource1 and bind it again. This way the grid will reflect the newly inserted record.
hope this will help you.