首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

DropDownList1的数据绑定有关问题

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

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()

热点排行