1

我有一个带有 EnableAutoPostBack 和两个 SqlDataSources 的下拉列表。

我想要做的是,如果用户选择 radiobuttonRed,那么 DDLType 将使用 SqlDataSourceRed 并根据所选的 DDLTYpe 项目将数据显示到网格视图中。

如果用户选择 radiobuttonBlue,则 DDLType 将使用 SqlDataSourceBlue 并根据所选的 DDLTYpe 项目将数据显示到网格视图中。

我怎样才能做到这一点?

4

1 回答 1

2

您将需要两个 SqlConnection 对象,其中包含到每个数据库的连接字符串:

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();
于 2013-06-21T17:54:08.197 回答