日期:2014-05-19  浏览次数:20483 次

请问,怎么实现DropDownList和TextBox之间的联动!!!
在做的一个系统当中,
数据库表U_user中有这样的关系:
name         mobile
张三         13333354545
李四         13525451245
王五         13548451245

现在有这么一个功能,从数据库当中取出用户名name绑定到DropDownList(id=car_user)中,我想当用户选中选择的DropDownList中的用户名的时候,下面有一个TextBox(id=car_usermobile)自动变成给该用户名的手机号。于是我在选择触发事件中这样做:
private   void   car_user_SelectedIndexChanged(object   sender,   System.EventArgs   e)
{

string   SqlConn=System.Configuration.ConfigurationSettings.AppSettings[ "ConnString "];//连接数据库
SqlConnection   Conn=new   SqlConnection(SqlConn);
Conn.Open();//打开连接
DataSet   ds=new   DataSet();
string   SqlStr_1= "select   mobile   from   [U_user]   where   name= ' "+this.car_user.SelectedItem.Text+ " ' ";
SqlDataAdapter   da=new   SqlDataAdapter(SqlStr_1,Conn);
da.Fill(ds, "user ");
this.car_usermobile.Text=ds.Tables[ "user "].Rows[0][0].ToString();
this.car_usermobile.DataBind();
Conn.Close();
}
但是这样结果是,用户选择的时候,下面TextBox中连反映都没有,请问是什么问题,又可以怎样实现??谢谢!

------解决方案--------------------
DropDownList autopostback=true
------解决方案--------------------
Autopostback 设为 True
------解决方案--------------------
DropDownList加属性:AutoPostBack= "True "