表结构如下
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我的代码那样写不行 大家帮我改下~~谢谢~~

解决方案 »

  1.   

    select DISTINCT companyid,a+b from
      

  2.   

    方法一:Sql语句中进行合并
    select  c = convert(nvarchar, a) + convert(nvarchar, b ) from templateinfo方法二:先得到DataTable,然后处理DataTable增加一个字段将两列合并
      

  3.   

    foreach (DataRow dRow in DSet.Tables[0].Rows)
            {
                ListItem LItem = new ListItem(dRow[DataTextValue].ToString() + "  " + dRow[DataTextFiled].ToString(), dRow[DataTextValue].ToString());
                drpList.Items.Add(LItem);
            }