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.