表结构如下
a b
1 2
3 4
5 6
绑定DropDownList怎么样才可以把ab两个字段的内容连接起来显示在下拉框里啊
string comstr1="select DISTINCT companyid from templateinfo";
con.Open();
SqlCommand cmd1=new SqlCommand(comstr1,con);
SqlDataReader dr1=cmd1.ExecuteReader();
this.DropDownList2.DataSource=dr1;
this.DropDownList2.DataTextField="a"+"b";
this.DropDownList2.DataBind();
con.Close();
效果应该是下拉12,23,34我的代码那样写不行 大家帮我改下~~谢谢~~
a b
1 2
3 4
5 6
绑定DropDownList怎么样才可以把ab两个字段的内容连接起来显示在下拉框里啊
string comstr1="select DISTINCT companyid from templateinfo";
con.Open();
SqlCommand cmd1=new SqlCommand(comstr1,con);
SqlDataReader dr1=cmd1.ExecuteReader();
this.DropDownList2.DataSource=dr1;
this.DropDownList2.DataTextField="a"+"b";
this.DropDownList2.DataBind();
con.Close();
效果应该是下拉12,23,34我的代码那样写不行 大家帮我改下~~谢谢~~
select c = convert(nvarchar, a) + convert(nvarchar, b ) from templateinfo方法二:先得到DataTable,然后处理DataTable增加一个字段将两列合并
{
ListItem LItem = new ListItem(dRow[DataTextValue].ToString() + " " + dRow[DataTextFiled].ToString(), dRow[DataTextValue].ToString());
drpList.Items.Add(LItem);
}