连接两个 ObjectDataSource

发布于 2024-09-29 07:44:36 字数 1749 浏览 1 评论 0原文

我需要连接两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2024-10-06 07:44:36

刚刚开始工作,这就是我所做的:

<asp:ObjectDataSource ID="OrderObjectDataSource" runat="server"/>
<asp:ObjectDataSource runat="server" ID="AdvertiserObjectDataSource" />

private Order _order;

protected void Page_Load(object sender, EventArgs e)
{
     OrderObjectDataSource.TypeName = "MyProject.Business.Repositories.OrderRepository";
     OrderObjectDataSource.SelectMethod = "GetById";
     OrderObjectDataSource.SelectParameters.Clear();
     OrderObjectDataSource.SelectParameters.Add(new QueryStringParameter("orderId", 
                                                    DbType.Int32, Proposal_Id_QS_Key));
     OrderObjectDataSource.Selected += OrderObjectDataSource_OnSelected;    
     AdvertiserObjectDataSource.TypeName = "MyProject.Business.Repositories.AdvertiserRepository";
     AdvertiserObjectDataSource.SelectMethod = "GetAdvertiserById";
     AdvertiserObjectDataSource.SelectParameters.Clear();
     AdvertiserObjectDataSource.SelectParameters.Add(new Parameter("advertiserId", DbType.Int32));
     AdvertiserObjectDataSource.Selecting += AdvertiserObjectDataSource_OnSelecting;

     OrderObjectDataSource.Select();
}


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;
}

Just got it working, here is what I've done:

<asp:ObjectDataSource ID="OrderObjectDataSource" runat="server"/>
<asp:ObjectDataSource runat="server" ID="AdvertiserObjectDataSource" />

private Order _order;

protected void Page_Load(object sender, EventArgs e)
{
     OrderObjectDataSource.TypeName = "MyProject.Business.Repositories.OrderRepository";
     OrderObjectDataSource.SelectMethod = "GetById";
     OrderObjectDataSource.SelectParameters.Clear();
     OrderObjectDataSource.SelectParameters.Add(new QueryStringParameter("orderId", 
                                                    DbType.Int32, Proposal_Id_QS_Key));
     OrderObjectDataSource.Selected += OrderObjectDataSource_OnSelected;    
     AdvertiserObjectDataSource.TypeName = "MyProject.Business.Repositories.AdvertiserRepository";
     AdvertiserObjectDataSource.SelectMethod = "GetAdvertiserById";
     AdvertiserObjectDataSource.SelectParameters.Clear();
     AdvertiserObjectDataSource.SelectParameters.Add(new Parameter("advertiserId", DbType.Int32));
     AdvertiserObjectDataSource.Selecting += AdvertiserObjectDataSource_OnSelecting;

     OrderObjectDataSource.Select();
}


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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文