I have a dropdown and a gridview.
The gridview datasource is dependent on dropdown.SelectedValue
The dropdown:
<asp:DropDownList ID="DropDownListLoggedInUser" runat="server" autopostback="True"
DataSourceID="SqlDataSource3" DataTextField="Medarbejder"
DataValueField="Medarbejder"
onload="DropDownListLoggedInUser_Load">
</asp:DropDownList>
It's datasource:
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:EGWebtidConnectionString %>"
SelectCommand="SELECT [Medarbejder] FROM [Sager] WHERE ([Medarbejder] IS NOT NULL)">
</asp:SqlDataSource>
The gridview:
<asp:GridView ID="GridViewSagsoversigt" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" Style="text-align: left" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnPreRender="GridViewSagsoversigt_PreRender" DataKeyNames="Sagsnr" EnablePersistedSelection="True"
SelectedIndex="0" OnSelectedIndexChanged="GridViewSagsoversigt_SelectedIndexChanged">
Its datasource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EGWebtidConnectionString %>"
SelectCommand="SELECT Sagsnr, Arbejskort, Adresse, Postnr, [By], Beskrivelse, Bemaerkning, Ansvarlig, Medarbejder FROM Sager WHERE ([Medarbejder] LIKE '%' + @Medarbejder + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownListLoggedInUser" Name="Medarbejder"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
When the page loads. The Gridview asks for Dropdown.SelectedValue, before Dropdown has fully loaded and set a SelectedValue. So SelectedValue returns "" and the Gridview shows nothing.
When I click on the dropdown and choose a name, it does a postback and it all works as planned.
So how can I make sure, that dropdown loads first and gridview loads second?