I have below code & i want to display in Jquery Datatable.
if (!this.IsPostBack)
{
RestClient restClient = new RestClient("http://localhost:40991/api/Employees");
restClient.Timeout = -1;
RestRequest request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
IRestResponse result = restClient.Execute(request);
var response = restClient.Execute(request);
if (response.Content == null)
throw new Exception(response.ErrorMessage);
}
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
45 Points
175 Posts
Consume Api using RestSharp
Feb 23, 2021 06:15 AM|jagjit saini|LINK
Hi
I have below code & i want to display in Jquery Datatable.
Thanks
Participant
1620 Points
927 Posts
Re: Consume Api using RestSharp
Feb 23, 2021 09:13 PM|PaulTheSmith|LINK
What can you do and, more importantly, what can't you do?
Do you now anything about Jquery? Have you used it before?
Which datatable do you want to use? Have you used it before?
What work have you done on your requirement?
Contributor
2840 Points
840 Posts
Re: Consume Api using RestSharp
Feb 24, 2021 10:28 AM|Sean Fang|LINK
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):
Api returned values:
aspx:
Code behind:
Demo:
Hope helps.
Best regards,
Sean