Asp.Net中使用c#的MultiColumn DropDownList

本文关键字:MultiColumn DropDownList Net Asp | 更新日期: 2023-09-27 18:25:09

我试图在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'.

知道我哪里错了吗?

谢谢。

Asp.Net中使用c#的MultiColumn DropDownList

您的SQL语句没有为CONVERT操作提供列名:

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

更改为:

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