日期:2014-05-18  浏览次数:20463 次

获取DropDownList控件的值出现问题!兄弟们帮帮忙!
//数据绑定
SqlDataReader   sdr   =   comm.ExecuteReader();
this.DropDownList1.DataSource=sdr;
this.DropDownList1.DataTextField= "ClassName ";
this.DropDownList1.DataValueField= "ClassID ";
this.DropDownList1.DataBind();

//获取下拉列表的值
this.DropDownList1.SelectedValue;
用这条语句出现错误,在网上搜过,说是版本问题
然后换成:
this.DropDownList1.SelectedItem.Value;
可是获取的值都是索引最小的那一个,怎么解决

------解决方案--------------------
SqlDataReader sdr = comm.ExecuteReader();
this.DropDownList1.DataSource=sdr;
this.DropDownList1.DataTextField= "ClassName ";
this.DropDownList1.DataValueField= "ClassID ";
this.DropDownList1.DataBind();

这个放到if(!isPostBack){}里面
------解决方案--------------------
数据在哪里绑定的,如果是在Page_Load里,绑定代码放

if(!Page.IsPostBack)
{

}

里试下
------解决方案--------------------
UP
------解决方案--------------------
有道理
------解决方案--------------------
try
this.TextBox1.Text = this.DropDownList1.SelectedItem.Text;
------解决方案--------------------
SqlDataReader sdr = comm.ExecuteReader();
datareader?
------解决方案--------------------
贴你绑定和取值全部相关代码看下