1

I want to use jquery Datatables plugin with ASP.Net GridView in a web forms project. I have gone through this link and have successfully managed to display the data in the grid along with other functionalities such as sorting/paging etc. The problem starts when I think about using RowCommand/RowDataBound events for the gridview. For ex - there's an image icon on each row to perform some sort of server side coding (for ex - deleting the record). I do not prefer creating handlers/web services for all such icons and want to know if this is at all possible?

Please let me know your thoughts.

Community
  • 1
  • 1
Nitesh
  • 2,286
  • 2
  • 43
  • 65

2 Answers2

2

As I understand it is working fine with you until you make any postback, so you need to write your javascript code that handles your inside pageLoad() event using javascript for example if you use:

$('#' + '<%=YourGridView.ClientID%>').DataTable();

Replace it with:

function pageLoad() 
{           
    $('#' + '<%=lstActive.ClientID%>').DataTable();
}

If you used that you will find that any postback will fire the DataTable function.

Saravanan Sachi
  • 2,572
  • 5
  • 33
  • 42
Ezz wahid
  • 21
  • 5
  • I want to load the data server side after the page has not loaded not loading the data on page load. This is something that can be done without using .ClientID – Nitesh Aug 22 '17 at 05:58
0

Add the following code to the GridView Prerender, it will add the header section to the gridview

protected void MyGrid_PreRender(object sender, EventArgs e)
{
   if (MyGrid.HeaderRow != null)
   {
      MyGrid.UseAccessibleHeader = true;
      MyGrid.HeaderRow.TableSection = TableRowSection.TableHeader;
   }
}
KE50
  • 546
  • 1
  • 7
  • 17
  • The question is more about server side data loading. This code will just add tag to gridview – Nitesh Oct 01 '17 at 05:38