我已经创建了一个简单的ASP Gridview,它使用一个ObjectDataSource从我的数据库中获取数据并在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是用于过滤我的GridView的DropDownList。它被放在一个<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,但是PostBack对其他功能很重要,所以我不能把它留在AutoPostBack="false"上,它必须一直在True上。
我的问题是:我如何防止这种情况发生。我想把AutoPostBack保留在DropDownList上。但是我的SelectMethod不应该同时触发。我希望能够控制何时使用搜索按钮过滤我的数据。
发布于 2019-03-26 23:33:30
你可以使用更新面板来防止selectIndex上的自动回发我遇到了sam问题,最近我想创建一个级联下拉菜单,我不想让页面在选定的索引更改时重新刷新。如果你想知道更多,这个教程有你的问题https://www.aspsnippets.com/Articles/Cascading-DropDownList-for-CountryStateCity-in-ASPNet.aspx的解决方案。
否则,您的代码应该如下所示。
<div class="grid-100">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<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>
</ContentTemplate>
<Triggers>
<asp:AsyncPostbackTrigger ControlID="DropDownListXY" EventName="SelectedIndexChanged" />
<asp:PostBackTrigger ControlID="btnConfirmPurchases" />
</Triggers>
</asp:UpdatePanel>
</div>希望这能有所帮助。:)
发布于 2019-04-01 17:18:23
第一个方法: true我已经使用了这个方法它是有效的,将这个添加到您的dropdown onchange="javascript:setTimeout('__doPostBack(\'DropDownListXY\',\'\')',0)",并确保设置为
<div class="grid-100">
<asp:DropDownList ID="DropDownListXY" OnSelectedIndexChanged="DropDownListXY_SelectedIndexChanged" DataSourceID="ObjectDataSourceApplikationTyp" runat="server" DataValueField="test_guid" DataTextField="test" AppendDataBoundItems="true" onchange="javascript:setTimeout('__doPostBack(\'DropDownListXY\',\'\')', 0)" AutoPostBack="true">
<asp:ListItem Text="-- all --" Value=""></asp:ListItem>
</asp:DropDownList>
</div>的第二个方法是将Dropdownlist放在UpdatePanel中,并在触发器中处理它的回发
https://stackoverflow.com/questions/55244419
复制相似问题