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

DropDownList 如何代码加入值
代码如下:
    dpsh.Items.Add(new   ListItem( "是 "),   Convert.ToString( "是 "));  
发生如下错误:

“Add”方法没有采用“2”个参数的重载

------解决方案--------------------
1.从DS中绑定
this.dpdAreas.DataTextField = "AreaName ";
this.dpdAreas.DataValueField = "AreaID ";
this.dpdAreas.DataSource = DS;
this.dpdAreas.DataBind();

你的DS中必须有AreaName和AreaID两个字段


2.自定义数据绑定
for(int i = 10;i <= 50; i += 10)
{
ListItem ls = new ListItem();
ls.Text = i.ToString()+ "人 ";
ls.Value = i.ToString();
this.ddlDisplayNum.Items.Add(ls);
}
this.ddlDisplayNum.Items.Add(new ListItem( "全部 ", " "));
this.ddlDisplayNum.SelectedValue = "20 ";