ListView Control in ASP.NET 3.5 – 4
This post is an addition to these three posts:
• ListView Control in ASP.NET 3.5 – 1 (opens a new window)
• ListView Control in ASP.NET 3.5 – 2 (opens a new window)
• ListView Control in ASP.NET 3.5 – 3 (opens a new window)
It would be a better practice to read these three posts first.
Using InsertItemTemplate with ItemCommand
I will demonstrate how to utilize InsertItemTemplate and InsertCommand in order to add a new record to the Country table. First, add the buttons which will show and hide the InsertItemTemplate by using the InsertItemPosition property of ListView:

Their associated OnClick events are:

For the initial loading of the page, set InsertItemPosition property of the ListView to None:

Now, place the InsertItemTemplate somewhere between the ListView tags like the other templates:

Like I did in this post before for the Edit and Delete commands, I will add a similar custom routine for the Insert command inside the ItemCommand event:

View on the HTML presentation is now supposed to be like:

If “Show Insert” button is clicked:

Put some meaningful entries to the textboxes:

It’s there, inserted:

Also, pay attention that “Hide Insert” button becomes “Show Insert” button.
Download
For more hands-on understanding of this post, you can download the sample (by VWD 2008) via here.
What is new LINQ Data Source?
Sanand
September 29, 2008 at 7:36 AM
Sanand,
MSDN – http://msdn.microsoft.com/en-us/library/bb547113.aspx
Great samples – http://mattberseth.com/blog/linqdatasource/
Hope these links will give you an idea.
Mustafa Basgun
September 30, 2008 at 5:32 PM
Nice article.
Please suggest how to use GroupTemplate and GroupKey to the group records. ListViews are powerful.
Thank you very much.
Paras
December 12, 2008 at 2:39 AM
I am a Business Intelligence Developer new to ASP.NET. This series of articles was very helpful. Thanks for taking the time to write it. It really saved me a lot of time!
David Russell
December 24, 2008 at 12:19 AM
Hi Mustafa. It is very helpful for a new ASP.NET 3.5 learner. Nicely explained.
Milind Mahajan
September 17, 2009 at 9:35 AM