Display, Edit , Update and delete data using DataListin Asp.Net and C#
DataList control is a data bound control which display repeated list of item of database.Manupulation of data in DataList is possible. We can edit and delete data in DataList. DataList control can be bound with database tables, xml file or other list of item (Array,ArrayList,Collections,Hash Table etc.).
Unlike GridView ,DataList does not have any default template to display data. So Developers has to use templates like ItemTemplate or EditItemTemplate to display data in DataList control.
DataList support some command name for button control for the manupulation of data.
DataList Support following command name-
Edit—call edit item event of DataList
Update—call update item event of DataList
Delete—call item deleted event of DataList
Cancel – call cancel edit event of DataList.
You can also give your own command name in DataList.
Here I am giving an example of how we can display ,edit , update and delete data using DataList control of Asp.Net.
DataList uses templates to display ,edit and update data. Common templates are given below:
ItemTemplate- Item Template define how to display data in DataList control
EditItemTemplate-- Edit Item Template define how to display data for editing
I have used followin database table in my example. Use following script to create table in your sql server databae
Use following code in your .aspx page
Write followin code in your page_load event
Following method will bind DataList to database
Below is edit event of grid view which will fire when user click on edit button
Now here is update event which will fire when user click on update button
Below is canceling event, fire when user click on cancel button with command name cancel