Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
I have created a Web API and I need to use the "Get" service in an asp web form in  a Grid View, how could I do this?


What I have tried:

I have created a Web API and I need to use the "Get" service in an asp web form in a Grid View, how could I do this?
Posted
Updated 29-Dec-21 1:36am

GridView is a server-side data control and it would make your life easier when manipulating it at the server because you can take advantage of the built-in features it offers. If you want to use Web API to populate your form then you might want to generate the html by hand or perhaps use a client-side grid that you can easily manage. For example Add, Edit, Delete In jqGrid With ASP.NET Web API – TechBrij[^]

If you really want to achieve what you want then here's an example that consumes a Web API and bind the result to GridView: How to Consume Web API Using Web Request[^]
 
Share this answer
 
You can do this in the following ways:

1) In the grid view's row data bound event set the server click event and process the business logic directly bypassing the service or call the service. For this to work asynchronously you will need to enclose the grid in an update panel.

2) In the grid view's row data bound event set the client click event of the control and bind it to the javascript function which will raise the web api service call.

3) In the grid's row bound event add custom attributes to the control whose click event you have to wire up with the service call. Then in the JavaScript when the page loads find the control using jQuery's or Html's attribute selector and bind its click event with the service call function.

-Nitij
 
Share this answer
 
 
Share this answer
 
v2
Comments
CHill60 29-Dec-21 7:46am    
Posting a link to our Homepage might be flattering but it isn't a solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900