如何把两个字段绑定到一个下拉框控件上?
我在数据库中存储了两个字段: provinceName porvinceNameEn
在绑定下拉框控件上显示时,我想把两个字段和在一起显示出来,请教如何实现?
我绑定一个代码如下:
string provinceListSql = "select * from HotelProvince ";
SqlConnection provinceListConn = new SqlConnection(strConnection);
SqlDataAdapter provinceListCmd = new SqlDataAdapter(provinceListSql,strConnection);
DataSet ds = new DataSet();
provinceListCmd.Fill(ds, "HotelProvince ");
provinceID.DataSource = ds.Tables[ "HotelProvince "].DefaultView;
provinceID.DataTextField = "provinceName ";
provinceID.DataValueField = "provinceID ";
provinceID.DataBind();
------解决方案--------------------provinceID.Items.Add(new ListItem( "显示的文本 ", "值 "));
------解决方案--------------------list <xxx> objlist=ds.Tables[ "HotelProvince "].DefaultView
foreach (xxx objxxx in objList)
{
this.provinceID.Items.Add(new ListItem( "【objxxx.porvinceNameEn】 " + objxxx.provinceName,objxxx.provinceID.ToString());
}
------解决方案--------------------using System.Collections.Generic;
命名空间
------解决方案--------------------不要告诉我你真的用list <xxx> ?? xxx我只是一个形容,你把他该成你实体类的命名 没有就用string
------解决方案--------------------list <string> objlist=ds.Tables[ "HotelProvince "].DefaultView //用来放你在数据裤查询到的值
foreach (string objxxx in objList) //循环数据记录
{
}
------解决方案--------------------string provinceListSql = "select *,provinceNameEn+provinceName AS ProName from HotelProvince ";
SqlConnection provinceListConn = new SqlConnection(strConnection);
SqlDataAdapter provinceListCmd = new SqlDataAdapter(provinceListSql,strConnection);
DataSet ds = new DataSet();
provinceListCmd.Fill(ds, "HotelProvince ");
provinceID.DataSource = ds.Tables[ "HotelProvince "].DefaultView;
provinceID.DataTextField = "ProName ";
provinceID.DataValueField = "provinceID ";
provinceID.DataBind();