User-1330468790 posted
Hi jagjit saini,
Before providing you with the solution, I recommend that you can directly use server processing mode of the jQuery Datatables with the web api url.
Within the current codes, I think you could fetch the values from the api
and bind the data to the grid view control.
Then, in the page load function, you could use the client id of the grid view control and
make it decorated with DataTables.
More details, you could refer to below codes:
model (Employee):
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
}
Api returned values:
new List<Employee>
{
new Employee{Id=1,Name="Name1"},
new Employee{Id=2,Name="Name2"},
new Employee{Id=3,Name="Name3"}
}
aspx:
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</form>
<script>
$(function () {
$("#<%=GridView1.ClientID%>").DataTable();
})
</script>
Code behind:
if (!this.IsPostBack)
{
// change the port number as yours
RestClient restClient = new RestClient("https://localhost:40991/api/GetEmployees");
restClient.Timeout = -1;
RestRequest request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
var response = restClient.Execute<List<Employee>>(request);
if (response.Content == null)
throw new Exception(response.ErrorMessage);
GridView1.DataSource = response.Data;
GridView1.DataBind();
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
Demo:

Hope helps.
Best regards,
Sean