ListView Control in ASP.NET 3.5 – 4
This post is an addition to these three posts:
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.