【发布时间】:2019-08-10 04:22:25
【问题描述】:
我创建了一个简单的带有ObjectDataSource 的ASP Gridview 来从我的数据库中获取数据并将其显示在GridView 中。 ObjectDataSource 看起来像这样:
<asp:ObjectDataSource
ID="ObjectDataSourceTest"
runat="server"
SelectMethod="GetTestData"
TypeName="DataManager"
<SelectParameters>
<asp:Parameter Name="sortExpression" Type="String" />
<asp:ControlParameter ControlID="DropDownListXY" Name="xyFilter" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
ControlParameter 是一个DropDownList,用于过滤我的GridView。它位于<asp:Panel> 中,如下所示:
<div class="grid-100">
<asp:DropDownList ID="DropDownListXY" OnSelectedIndexChanged="DropDownListXY_SelectedIndexChanged" DataSourceID="ObjectDataSourceApplikationTyp" runat="server" DataValueField="test_guid" DataTextField="test" AppendDataBoundItems="true" AutoPostBack="true">
<asp:ListItem Text="-- all --" Value=""></asp:ListItem>
</asp:DropDownList>
</div>
我的问题是,每当我从DropDownList 中选择某些东西时,它都会触发SelectMethod。我尝试在DropDownList 上关闭AutoPostBack,但回发对于其他功能很重要,所以我不能将它留在AutoPostBack="false" 上,它必须一直在True 上。
我的问题是:我怎样才能防止这种情况发生。我想将AutoPostBack 保留在DropDownList 上。但是我的 SelectMethod 不应该同时触发。我希望能够控制何时使用搜索按钮过滤我的数据。
【问题讨论】:
-
换个策略怎么样。在您的 SelectMethod
GetTestData中,您能否检测到它由于 DropDownList 更改而正在运行,然后退出?
标签: c# asp.net gridview postback objectdatasource