如何在网格视图中的ASP Web表单中使用Web API [英] How I could use web API in an ASP web forms in grid view

查看:107
本文介绍了如何在网格视图中的ASP Web表单中使用Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?





我尝试了什么:



我创建了一个Web API,我需要在asp web表单中使用Get服务一个网格视图,我怎么能这样做?



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?

推荐答案

GridView是一个服务器端数据控件,它可以让你在服务器上操作它时生活更轻松,因为你可以利用它提供的内置功能。如果您想使用Web API填充表单,那么您可能希望手动生成html,或者使用您可以轻松管理的客户端网格。例如,使用ASP.NET Web API添加,编辑,删除jqGrid– TechBrij [ ^ ]



如果你真的想达到你想要的,那么这里是一个使用Web API并将结果绑定到GridView的例子:如何使用Web请求使用Web API [ ^ ]
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[^]


您可以通过以下方式执行此操作:



1)在网格视图的行数据绑定事件中设置服务器单击事件并直接处理业务逻辑绕过服务或调用服务。为了使其异步工作,您需要将网格包含在更新面板中。



2)在网格视图的行数据绑定事件中设置客户端单击事件控制并将其绑定到javascript函数,这将引发web api服务调用。



3)在网格的行绑定事件中,将自定义属性添加到其click事件的控件中你必须连接服务电话。然后在JavaScript加载页面时使用jQuery或Html的属性选择器找到控件并将其click事件与服务调用函数绑定。



-Nitij
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


这篇关于如何在网格视图中的ASP Web表单中使用Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆