链接两个 ObjectDataSource
我的问题场景如下:
我有一个 GridviewA 绑定到 objectdatasourceA。当我单击 GridviewA 行时,我希望另一个 objectdatasourceB 从 GridViewA 中选取 ID,然后获取 GridviewB 的记录。这就像主细节。
我可以做到这一点以及如何使用 javascript/jqueryscript 使其顺利进行。
My problem scenario is as follows:
I have one GridviewA bound to a objectdatasourceA. When I click on a GridviewA row, I want another objectdatasourceB to pick the ID from the GridViewA and then fetch records for GridviewB. This is like masterdetail.
Can i do this and how to use javascript/jqueryscript to make it smooth.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的内部对象数据源应该是这样的
Your inner objectdatasource should be look like
首先确保您已将 gridview A 上的 dataKey 属性设置为基础对象的 ID 属性(或您想要传递给 objectDataSource B 的 select 方法的任何内容),
然后转到 objectDataSource B,配置它,选择您的 select 方法接受参数,然后单击下一步。它会问你从哪里获取该参数(我认为你可以在控件、会话和其他东西之间进行选择)并选择控件,它将填充页面上所有控件的列表并选择你的 gridview A。
这将传递将所选行的 dataKey 从 gridview A 传输到链接到 objectDataSource B 的方法。选择代码将运行,然后 gridview B 将显示所需的子集。如果您在 gridView A 中选择一个新行,它将自动更新 gridview B 以显示所需的数据。
假设你的方法设置正确,你几乎不需要编写任何代码就可以做到这一点。如果您打算这样做,请查看一些可用的缓存方法,因为根据记录集的大小,它可能会占用相当大的带宽。
firstly make sure you have set the dataKey property on your gridview A to be the ID property of the underlying object (or whatever you want to pass through to objectDataSource B's select method)
then go to objectDataSource B, configure it, choose your select method which accepts a parameter, and then click next. it will ask you where to get that parameter from (i think you can choose between control, session and something else) and select control, it will populate a list of all the controls on the page and select your gridview A.
this will pass on the selected rows dataKey from gridview A to the method linked to objectDataSource B. the select code will run and your gridview B will then display the required subset. if you select a new row in gridView A, it will automatically update gridview B to show the required data.
you can do this with pretty much no code behind written assuming your methods are set up correctly. if you are going to do this have a look at some of the caching methods available as it can be quite bandwidth heavy depending on the size of your recordsets..