Personal Blog of Mustafa Basgun

ListView Control in ASP.NET 3.5 – 4

with 6 comments

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.


For more hands-on understanding of this post, you can download the sample (by VWD 2008) via here.


Written by Mustafa Basgun

December 30, 2007 at 5:00 PM

6 Responses

Subscribe to comments with RSS.

  1. What is new LINQ Data Source?


    September 29, 2008 at 7:36 AM

  2. Sanand,

    MSDN –

    Great samples –

    Hope these links will give you an idea.

    Mustafa Basgun

    September 30, 2008 at 5:32 PM

  3. Nice article.

    Please suggest how to use GroupTemplate and GroupKey to the group records. ListViews are powerful.

    Thank you very much.


    December 12, 2008 at 2:39 AM

  4. 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

  5. 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

  6. Thanks for posting this. Helpful to see programmatic handling of events instead of just letting the datasource control do everything for you like most examples show.


    December 4, 2009 at 1:19 PM

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: