连接两个 ObjectDataSource
我需要连接两个 ObjectDataSource 标签。 第一个将有一个查询字符串参数,第二个有一个参数,该参数是第一个结果集中的字段之一。该关系是一对一的,因此我无法将第二个放在网格中并使用控制参数
<asp:ObjectDataSource ID="OrderObjectDataSource" runat="server"
SelectMethod="GetById"
TypeName=" MyProject.Business.Repositories.OrderRepository"
OnSelected="OrderObjectDataSource_OnSelected">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="86" Name="orderId"
QueryStringField="ioid" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource runat="server" ID="AdvertiserObjectDataSource"
TypeName="MyProject.Business.Repositories.AdvertiserRepository"
SelectMethod="GetAdvertiserById"
OnSelecting="AdvertiserObjectDataSource_OnSelecting">
<SelectParameters>
<asp:Parameter Name="advertiserId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</asp:Content>
private Order _order;
protected void OrderObjectDataSource_OnSelected(object source, ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue != null)
{
_order = (Order) e.ReturnValue;
AdvertiserObjectDataSource.SelectParameters["advertiserId"].DefaultValue =
_order.AdvertiserId.ToString();
AdvertiserObjectDataSource.Select();
}
}
protected void AdvertiserObjectDataSource_OnSelecting(object source, ObjectDataSourceSelectingEventArgs e)
{
if (_order != null)
e.InputParameters["advertiserId"] = _order.AdvertiserId;
}
这不起作用,因为 AdvertiserObjectDataSource_OnSelecting 在 OrderObjectDataSource_OnSelected 之前调用。
感谢您的帮助。
I need to connect two ObjectDataSource tags.
First will have a query string parameter and the second has a parameter, which is one of the fields in the result set of the first one. The relationship is one-to-one, so I can't put second one in a grid and use control parameter
<asp:ObjectDataSource ID="OrderObjectDataSource" runat="server"
SelectMethod="GetById"
TypeName=" MyProject.Business.Repositories.OrderRepository"
OnSelected="OrderObjectDataSource_OnSelected">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="86" Name="orderId"
QueryStringField="ioid" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource runat="server" ID="AdvertiserObjectDataSource"
TypeName="MyProject.Business.Repositories.AdvertiserRepository"
SelectMethod="GetAdvertiserById"
OnSelecting="AdvertiserObjectDataSource_OnSelecting">
<SelectParameters>
<asp:Parameter Name="advertiserId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</asp:Content>
private Order _order;
protected void OrderObjectDataSource_OnSelected(object source, ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue != null)
{
_order = (Order) e.ReturnValue;
AdvertiserObjectDataSource.SelectParameters["advertiserId"].DefaultValue =
_order.AdvertiserId.ToString();
AdvertiserObjectDataSource.Select();
}
}
protected void AdvertiserObjectDataSource_OnSelecting(object source, ObjectDataSourceSelectingEventArgs e)
{
if (_order != null)
e.InputParameters["advertiserId"] = _order.AdvertiserId;
}
This does not work because AdvertiserObjectDataSource_OnSelecting is called before OrderObjectDataSource_OnSelected.
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚开始工作,这就是我所做的:
Just got it working, here is what I've done: