2015-05-07 37 views
2

我嵌套了GridView。当我展开外部行时,它显示内部GridView。这两个gridviews都在UpdatePanel中,并使用ObjectDataSource来填充数据。ObjectDataSource在嵌套GridView中调用多次

当我点击expand时,我通过单击通过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> 
+0

看到这个https://msdn.microsoft.com/en-us/library/aa479353(d=printer).aspx –

回答

0

我有两种处理方法这一点。

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"; 
} 
  • 我真的不关心我如何处理这上面,所以前进在我的选择方法,我缓存中的数据,持续10秒(长,如果我需要)我允许该方法再次运行,但返回缓存的数据与再次敲击数据库。