Apollo
Apollo

Reputation: 2070

DropDownList with Two SqlDataSources

I have a single dropdownlist with EnableAutoPostBack and two SqlDataSources.

What I am trying to do is if user chooses radiobuttonRed then the DDLType will use SqlDataSourceRed and display data into a gridview depending on DDLTYpe item selected.

If the user chooses radiobuttonBlue then the DDLType will use SqlDataSourceBlue and display the data into a gridview depending on DDLTYpe item selected.

How can I achieve this?

Upvotes: 1

Views: 68

Answers (1)

Cameron Tinker
Cameron Tinker

Reputation: 9789

You would need two SqlConnection objects with connection strings to each database:

SqlConnection connRed = new SqlConnection();
SqlConnection connBlue = new SqlConnection();
DataTable dt = null;
SqlDataAdapter da = null;

if(radioButtonRed.Checked)
{
    dt = new DataTable();
    da = new SqlDataAdapter("select command", connRed);   
}
else
{    
    dt = new DataTable();
    da = new SqlDataAdapter("select command", connBlue);
}

da.Fill(dt);
dgv.DataSource = dt;
dgv.DataBind();

Upvotes: 2

Related Questions