读书人

DropDownList SelectedValue 有关问题

发布时间: 2012-04-23 13:17:38 作者: rapoo

求助 DropDownList SelectedValue 问题
DropDownList4.DataTextField = "classxname";
DropDownList4.DataValueField = "classxid";
string cla = dr["classxid"].ToString();
DropDownList4.SelectedValue = cla;
DropDownList4.DataBind();


这里 cal="4";
可就是DropDownList4.SelectedValue ="";

不知道 怎么会这样

在前面有一个DropDownList1 赋值是成功的,然后DataBind();

[解决办法]
DropDownList4.DataSource= xxx;
DropDownList4.DataTextField = "classxname";
DropDownList4.DataValueField = "classxid";
DropDownList4.DataBind();
string cla = dr["classxid"].ToString();
Response.Write("cla=" + cla); //看有值吗
ListItem x = DropDownList4.Items.FintByValue(cla);
if(x!=null) x.Selected=true;


你的这个cla在列表中吗?是唯一的吗

读书人网 >asp.net

热点推荐