当前位置: 代码迷 >> ASP.NET >> DropDownList1的数据绑定有关问题
  详细解决方案

DropDownList1的数据绑定有关问题

热度:5227   发布时间:2013-02-26 00:00:00.0
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()