读书人

DropDownList1的数据绑定有关问题

发布时间: 2011-12-13 21:22:18 作者: rapoo

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

读书人网 >asp.net

热点推荐