I have a Dropdown list being populated by an SqlDataSource, with the following markup:
Dropdown:
<asp:DropDownList ID="SaleIDDropDown" runat="server" CssClass="dropdown"
DataSourceID="DropDownDataSource" DataTextField="Title" DataValueField="ID"
AppendDataBoundItems="true">
</asp:DropDownList>
DataSource
<asp:SqlDataSource ID="DropDownDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:SQL-DEV %>"
SelectCommand="SELECT [ID], [Title], [userid] FROM [AdSelect]">
</asp:SqlDataSource>
The problem I'm running into is when some of the data is changed via the web interface I'm making (I delete an item, or change it's Title for example) the Dropdown populates with the old data, even though it clearly has changed in the DataBase (I checked using SQL Server Studio). If I reload the page, then the Dropdown is finally populated correctly.
I need a way to "force" a refetching/selecting of the data, but my efforts have so far failed. I've tried doing it in code, but it's not taking effect.
DropDownDataSource.Select(DataSourceSelectArguments.Empty);
DropDownDataSource.DataBind();
SaleIDDropDown.DataBind();
It still doesn't update the dropdown, even when this is run.
How can I make the dropdown and its SqlDataSource and push it to the page on command?