i've created a simple ASP Gridview with an ObjectDataSource to get the data from my database and show it in the GridView. The ObjectDataSource looks like this:
<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>
The ControlParameter is a DropDownList that is used to filter my GridView. It's placed inside a <asp:Panel> and looks like this:
<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>
My problem is, that whenever i select something from the DropDownList it triggers the SelectMethod. I tried turning off the AutoPostBack on my DropDownList but the PostBack is important for other functions so i cant leave it on AutoPostBack="false" it has to be on True all the time.
My question is: How can i prevent this from happening. I want to keep the AutoPostBack on the DropDownList. But my SelectMethod should not trigger at the same time. I wanna be able to control when i filter my data with a search-button.
You can use a updatepanel to prevent autopostback on selectIndex I had the sam problem has you recently I wanted to create a cascading dropdown and I didnt want the page to refreash on selected index changed. If you wanted to known more this tutoriel has the solution too your problem https://www.aspsnippets.com/Articles/Cascading-DropDownList-for-CountryStateCity-in-ASPNet.aspx
Otherwise your code should look something like this.
Hope this helps. :)