Search code examples
c#dynamicsqldatasourcedropdownlistfor

SqlDataSource Based Dropdown list


I have created a dropdown list which fetched filtered data based on status.

But my already inserted data may have some entries that are not active at the moment. Initially I applied a DatasourceID to a dropdownlist

<asp:DropDownList ID="DDL_Country" runat="server" CssClass="roundDDL" 
                  DataSourceID="SDS_Country" 
                  DataTextField="Descr" DataValueField="Code">
</asp:DropDownList>

Now on a click I want to change the DatasourceId as per new SDS_Country_All

DDL_Country.DataSourceID = "SDS_Country_All";
DDL_Country.DataValueField = "Code";
DDL_Country.DataTextField = "Descr";

I have also tried to apply databound(); etc.

It is continuously giving me error.


Solution

  • You're getting a SQL error. Check the select statement for SDS_Country_All