【问题标题】:ObjectDataSource calling multiple times in nested gridview在嵌套的gridview中多次调用ObjectDataSource
【发布时间】:2015-05-07 05:52:30
【问题描述】:

我已经嵌套了 GridView。当我展开外部行时,它显示内部 GridView。两个网格视图都在 UpdatePanel 内,并使用 ObjectDataSource 填充数据。

当我点击展开时,我正在通过 JQuery 点击一个按钮来回帖。在这里,用于外部网格的 ObjectDataSource1 多次调用 SelectMethod。我检查了 UpdatePanel UpdateMode 是有条件的。

如何防止 ObjectDataSource 多次获取数据?

ASPX:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectCountMethod="GetDevicesCount" SelectMethod="GetDevices" TypeName="Flows" SortParameterName="sortExpression" EnablePaging="True">
    <SelectParameters>
        <asp:ControlParameter ControlID="txtSearch" Name="searchTerm" PropertyName="Text" Type="String" />
        <asp:ControlParameter ControlID="hdnFieldFromDate" Name="fromDate" PropertyName="Value" Type="String" />
        <asp:ControlParameter ControlID="hdnFieldToDate" Name="toDate" PropertyName="Value" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectCountMethod="GetFlowDetailsCount" SelectMethod="GetFlowDetails" OnSelecting="ObjectDataSource2_Selecting" TypeName="Flows" EnablePaging="True">
    <SelectParameters>
        <asp:ControlParameter ControlID="HiddenDeviceId" Name="deviceId" PropertyName="Value" Type="String" />
        <asp:ControlParameter ControlID="hdnFieldFromDate" Name="fromDate" PropertyName="Value" Type="DateTime" />
        <asp:ControlParameter ControlID="hdnFieldToDate" Name="toDate" PropertyName="Value" Type="DateTime" />
    </SelectParameters>
</asp:ObjectDataSource>

【问题讨论】:

标签: c# asp.net gridview objectdatasource


【解决方案1】:

我通过两种方式处理了这个问题。

1:在页面的 ASPX 端将选择方法设置为 SelectMethod = "" 并在页面为回发时分配它。

if (Page.IsPostBack)
{
    //Always set the select methods.
    SetSelectMethods();
}
else
{
    ODSGetOptionSearchDataCS.SelectMethod = string.Empty;
    ODSWatchlistCS.SelectMethod = string.Empty;
}    

private void SetSelectMethods()
{
    ODSGetOptionSearchDataCS.SelectMethod = "GetOptionCondors";
    ODSWatchlistCS.SelectMethod = "GetOptionWLCondors";
}
  1. 我真的不在乎我是如何处理上述问题的,所以在我的选择方法中,我将数据缓存 10 秒(如果需要,可以更长)我允许该方法再次运行,但返回缓存的数据 vs . 再次访问数据库。

【讨论】:

    猜你喜欢
    • 2013-07-29
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 2011-04-23
    相关资源
    最近更新 更多