首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

获取DropDownList控件的值出现有关问题!兄弟们帮帮忙

2011-12-18 
获取DropDownList控件的值出现问题!兄弟们帮帮忙!//数据绑定SqlDataReadersdrcomm.ExecuteReader()this.

获取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?
[解决办法]
贴你绑定和取值全部相关代码看下

热点排行