Using SQLDatasource with Dropdownlist box
Ok, so setting up a dropdownlist box to be populated from a SqlDataSource control is not a big thing - - like so:
<asp: dropdownlist ID="ddlAllegs" RepeatColumns="2" runat="server"
Width="728px" Height="580px" DataSourceID="sdsAllegs"
DataTextField="Allegations" DataValueField="Alleg_ID">
</asp: dropdownlist >
<asp:SqlDataSource ID="sdsAllegs" runat="server"
ConnectionString="<%$ ConnectionStrings:MPEEC %>"
SelectCommand="SELECT[Alleg_ID],[Allegations]FROM [Aux_Allegations_Table]"></asp:SqlDataSource>
BUT now, when I do my Page Load and I want to call sub RetrieveData() where I want to set the dropdown selected item based upon a value retrieved from a table like so :
ddlAllegs.Items.FindByText(myDataReader("Allegatio ns")).Selected = True
BUT - the dropdownlist has not been loaded yet and the application throws and error. Hate to give up my new found favorite control, SqlDataSource, and be forced to go back to the old fashion way of manually populating.
Any Ideas?
|