Yet Another Blog on ASP.NET and Some Other Stuff

ListView Control in ASP.NET 3.5 - 4

Posted in ASP.NET, ListView, SQL, VB.NET, Web Development by Mustafa Basgun on December 30th, 2007

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.

Leave a Reply