日期:2014-05-17  浏览次数:20985 次

C#的DropDownList问题
我SQL有1个商品表,商品类型为A,商品ID为1.
我是动态绑定数据库的,我要怎么写代码才能
让我的下拉菜单里面显示的样式是  ID:类型 {1:A}?

请教各位大神!!!!
c# sql

------解决方案--------------------
现将数据表记录填充到DataTable里
然后绑定DropDownList

dropDownList1.DataSource=datable1;
dropDownList1.DisplayMember="商品类型";
dropDownList1.ValueMember="ID";
dropDownList1.DataBind();
------解决方案--------------------
引用:
那SQL文 怎么写 能说下嘛 我新手

select (convert(nvarchar,ID)+':'+ProductBigType) as content from table

------解决方案--------------------
引用:
引用:那SQL文 怎么写 能说下嘛 我新手
select (convert(nvarchar,ID)+':'+ProductBigType) as content from table

恩,你的是ID的话还是用varchar好
select (convert(varchar,ID)+':'+ProductBigType) as content from table
------解决方案--------------------
content   错误应该是下面 你用选中的数据 对数据库错做了吧 
------解决方案--------------------
引用:
那个(ID:名)实现了,但是有了个问题 我在联动第2个的DropDownList的时候,因为第1个里面的值变成了  (ID:名) sql就没有能=dropDownList.SelectedValue 相等的了。有没有办法 让他在
 if (!Page.IsPostBack)
           {
              
                S……


...
那你就多查一个字段。。

select (convert(varchar,ProductTypeNo)+':'+ProductTypeName) as content,ProductTypeNo from ProductTypeMaster where ProductType='1'