0

我正在使用 asp.net 2.0。我正在使用声明性数据源。对于后面代码中的某些内容,我想访问 Foo.Bar 返回的对象(在下面的示例中)。系统正在缓存它,所以我应该能够访问该版本,而不必重新调用 Foo.Bar()。我该怎么做呢?

<asp:ObjectDataSource ID="MyLuckDataSource1" runat="server" 
    TypeName="Foo.Bar" SelectMethod="GetMoreFoo" 
    CacheDuration="Infinite" CacheExpirationPolicy="Sliding" 
    EnableCaching="True">
    <SelectParameters>
        <asp:ControlParameter ControlID="BarID" Name="bar_code" Type="String" Direction="Input" DefaultValue="1011" />
    </SelectParameters>
</asp:ObjectDataSource>

<asp:GridView ID="GridView1" runat="server"  runat="server" DataSourceID="MyLuckDataSource1" ...
4

3 回答 3

1

试试 GridView 的 OnRowDataBound 事件。

就像:

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var some = (Foo.SomeBar) e.Row.DataItem;
        somelabel.Text = some.Date.ToString();
    }
}

附言。尝试一下,我的意思是它有效:)

于 2009-03-05T21:58:17.487 回答
0

我认为 Freddy 对 OnRowDataBound 的看法是正确的。虽然我认为您只能在gridview上绑定期间检查单元格的文本结果,而不是底层对象,但我不记得了。

至少在从 GetMoreFoo() 返回结果之前,您可以将结果存储在会话中。

我完成了整个模型视图展示器 (MVP) 的工作,并将对象数据源连接到展示器,因此当调用 GetMoreFoo() 函数时,我可以在视图 (aspx.cs) 或展示器上访问我想要的任何内容。

于 2009-03-05T22:00:41.943 回答
0

您还可以通过检查 e.ReturnValue 属性在 ObjectDataSource.Selected 事件中捕获您的收集结果。

protected void MyLuckDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
    List<Foo> x = (List<Foo>)e.ReturnValue;

    // do whatever you need with the results here...
}
于 2009-03-23T20:21:18.143 回答