代码
public void Bind_config_role(DropDownList ddl, int addRoot) { //获取dataset内容 SR.BLL.T_ConfigData bll = new SR.BLL.T_ConfigData(); DataSet dt = bll.GetAllItems();
// dt中存在字段‘Name’和‘Role’
//..........................新增字段....................................
// . . . .
// . . . .
// Ⅴ Ⅴ Ⅴ Ⅴ dt.Tables[0].Columns.Add("mergerName",typeof(string),"Name+'-'+Role");
// ddl.DataSource = dt.Tables[0].DefaultView; ddl.DataTextField = "mergerName"; ddl.DataValueField = "ID"; ddl.DataBind(); if (addRoot == 1) ddl.Items.Insert(0, new ListItem("", "0")); }
若字段Name里的值为“中国”,字段Role里的值为“北京”,那么下拉框selecttext输出值为“中国-北京”