您的位置:首页 > 数据库

DropDownList绑定显示数据库多个字段

2016-01-31 22:00 429 查看
正常的下拉框的绑定如下:

Hashtable hashtable = new Hashtable();
hashtable.Add("usertype", 3);
DataTable dt = this.GetTableListAll(hashtable);
this.DDL_LOGIN_NAME.DataSource = dt;
this.DDL_LOGIN_NAME.DataTextField = "name";
this.DDL_LOGIN_NAME.DataValueField = "id";
this.DDL_LOGIN_NAME.DataBind();


上面显示的text是name,如果需要显示name加上email,该如何呢

Hashtable hashtable = new Hashtable();
hashtable.Add("usertype", 3);
DataTable dt = this.GetTableListAll(hashtable);
for (int i = 0; i < dt.Rows.Count;i++ )
{
string strText = dt.Rows[i]["name"].ToString() + "|" + dt.Rows[i]["email"].ToString();
string strValue = dt.Rows[i]["id"].ToString(); ;

ListItem listItem = new ListItem
{
Text = strText,
Value = strValue
};

this.DDL_LOGIN_NAME.Items.Add(listItem);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: