我有一个省市级联的下拉列表用户控件region,我再aa.aspx中引用这个用户控件,通过FindControl可以获取的用户控件region中下拉列表的值,但是,我的aa.aspx是一个修改页面,是从一个数据的列表页点进去的,跳转的时候传了userId进去,在aa.aspx中通过userId获取到user对象,然后我想把user对象中的区域Id赋值给用户控件中的下拉列表,好让它在加载的时候就显示user对象的区域,但是下拉列表的SelectedValue却赋不上值,是怎么回事啊,求高人指点,我的代码是这样写的
DropDownList ddlPro = this.FindControl("regionbar").FindControl("ddlPro") as DropDownList;
DropDownList ddlCity = this.FindControl("regionbar").FindControl("ddlCity") as DropDownList;ddlCity.SelectedValue=user.regionid.tostring();[code=csharp][/code]但不知为何ddlCity.SelectedValue总是等于空,求高人指点啊!谢谢DropDownList用户控件Web
DropDownList ddlPro = this.FindControl("regionbar").FindControl("ddlPro") as DropDownList;
DropDownList ddlCity = this.FindControl("regionbar").FindControl("ddlCity") as DropDownList;ddlCity.SelectedValue=user.regionid.tostring();[code=csharp][/code]但不知为何ddlCity.SelectedValue总是等于空,求高人指点啊!谢谢DropDownList用户控件Web
http://www.cnblogs.com/insus/p/3154363.html
http://www.cnblogs.com/insus/archive/2013/03/14/2958871.html
http://www.cnblogs.com/insus/archive/2013/03/05/2943808.html
more user control related:
http://www.cnblogs.com/insus/category/341697.html
2:尝试用 this.drpSort.SelectedItem.Text=user.regionid.tostring();
你这样赋值是做什么的?你是增加值吧?!
ddlCity.Items.Insert( 0, new ListItem(user.regionid.tostring(), "0"));
ddlCity.SelectedIndex = 0;
1.首先user.regionid.tostring()不为空,是有值的
2.其次this.drpSort.SelectedItem.Text=user.regionid.tostring()这样写会出现“未将对象的引用设置到对象的实例”的错误信息
3.最后 是个女的没错,但不是个MM
4.最后的最后 我在哪里工作跟这个问题没有关系,总而言之还是要谢谢你
不是增加值的,就是想在加载的时候就把user.regionid赋值给ddlCity,也就想在页面加载之后ddlCity.SelectedValue的值显示的是user.regionid,只是我这个ddlCity是在一个用户控件中的
{
get { return this.ddlCity; }
set { this.ddlCity = value; }
}页面中代码如下:
ddlCity.SelectedValue =cityid.tostring();
这样就可以了,
假设用户控件的Id是uc
uc.GetCity.SelectedValue =cityid.tostring();
uc.GetCity得到的是用户控件中的DropDownList
这样就行了