In this blog, I will show how to use jQuery DataTable with the Delete button.
Why should we use jQuery Datatable
jQuery Datatable is very lightweight and gives us some inbuilt functionalities like searching and sorting etc.
In order to implement the jQuery Datatable, follow the below mentioned steps.
Step 1
Add jQuery script and jQuery Datatable CSS and JS inside the head section of the page. Below, I have given all those scripts.
- <!—Jquery Datatable css -->
- <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
- <!—Jquery Js script -->
- <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
- <!—Jquery Datatable js script -->
- <!-- DataTables -->
- <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
Step 2
Design the HTML table. In the below code, as you can see, I have assigned an id to the table and its body. Before moving to the next step, please be sure that your table is in a proper format.
- <table id="userTable">
- <thead>
- <tr>
- <th> User Name </th>
- <th>Email Id</th>
- <th> Address </th>
- <th>Mobile Number</th>
- <th>Action</th>
- </tr>
- </thead>
- <tbody id="tBody"> </tbody>
- </table>
Step 3
Go to code behind of the page to create a function which will return the data to bind the table. I have created a class UserList with five auto-implemented properties, as you can see in the below code.
- public class UserList {
- public string UserID {
- get;
- set;
- }
- public string UserName {
- get;
- set;
- }
- public string EmailId {
- get;
- set;
- }
- public string Address {
- get;
- set;
- }
- public string MobileNumber {
- get;
- set;
- }
- }
Step4
Now, create a method which will return the value to bind the table.
Note - Please focus on these points while creating a method.


Join the conversation! Your thoughts help the community grow.