使用c#在Asp.Net中的MultiColumn DropDownList

时间:2013-07-28 11:37:38

标签: c# asp.net sql

我试图在DropDownList菜单中显示2列。要做到这一点,

当我在SSMS中执行以下sql查询时,

"SELECT (convert(varchar,Cost_ID) +' , '+ Item_Description) FROM Cost_ID"

它带来了所需的输出。但是当我在Microsoft Visual Studio 2012数据源中添加它时,即

<asp:SqlDataSource ID="SqlDataSource12" runat="server" ConnectionString="Data Source=MEHDI-PC\SQLEXPRESS;Initial Catalog=PIMS;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT (convert(varchar,CostID) +' , '+ Item_Description) FROM Cost_ID"></asp:SqlDataSource>

运行程序时出现以下错误:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Cost_ID'.

知道我哪里错了吗?

谢谢。

1 个答案:

答案 0 :(得分:2)

您的SQL语句未提供CONVERT操作的列名:

SelectCommand="SELECT (convert(varchar,CostID) +' , '+ Item_Description) FROM Cost_ID"

将其更改为:

SelectCommand="SELECT (convert(varchar,CostID) +' , '+ Item_Description) Cost_ID FROM Cost_ID"