我有一个带有 EnableAutoPostBack 和两个 SqlDataSources 的下拉列表。
我想要做的是,如果用户选择 radiobuttonRed,那么 DDLType 将使用 SqlDataSourceRed 并根据所选的 DDLTYpe 项目将数据显示到网格视图中。
如果用户选择 radiobuttonBlue,则 DDLType 将使用 SqlDataSourceBlue 并根据所选的 DDLTYpe 项目将数据显示到网格视图中。
我怎样才能做到这一点?
您将需要两个 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();