日期:2014-05-19  浏览次数:20411 次

DropDownList1的数据绑定问题
我在aspx页面有两个SqlDataSource,分别是SqlDataSource1和SqlDataSource2

在CS页面里,根据传过来的值判断DropDownList1绑定到哪个数据源:
                if   (Request.QueryString[ "id "]   !=   null)
                        DropDownList1.DataSource   =   SqlDataSource2;
                       
                else
                        DropDownList1.DataSource   =   SqlDataSource2

可未什么我的DropDownList1总获不得SqlDataSource里的数据?我的SqlDataSource没有问题。。

求助。

------解决方案--------------------
if (Request.QueryString[ "id "] != null)
{
DropDownList1.DataSourceID = "SqlDataSource1 ";
DropDownList1.DataTextField = "name ";
DropDownList1.DataValueField = "id ";
DropDownList1.DataBind();
}
else
{
DropDownList1.DataSourceID = "SqlDataSource2 ";
DropDownList1.DataTextField = "name ";
DropDownList1.DataValueField = "id ";
DropDownList1.DataBind();
}
------解决方案--------------------
dropdownlist绑定:
1、datasource
2、DataValueField
3、DataTextField
4、DATABIND()