Monday, March 14, 2011

ListView Control in ASP.NET 3.5 – 4

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.

No comments:

Popular Posts