2016-08-11 70 views
1

我試圖綁定一個asp:DropDownList但我一直收到錯誤ASP.NET綁定的DropDownList拋出錯誤

類型「System.Web.HttpException」的異常出現在 System.Web.dll中,但在用戶代碼中沒有處理

其他信息:數據綁定:「System.Data.DataRowView」並不 不包含與「id_enabled」的名稱的屬性

這裏是我的SqlDataSource

<asp:SqlDataSource 
    ID="sql_enabled_ddl" 
    runat="server" 
    ConnectionString="<%$ ConnectionStrings:Tip-Tour %>" 

    SelectCommand ="SELECT 
         id_enabled, 
         description 

        FROM 
        (
         SELECT 
          1 AS id_enabled, 
          'true' AS description 

         UNION 

         SELECT 
          2 AS id_enabled, 
          'false' AS description 

        ) AS passport_enabled"> 

</asp:SqlDataSource> 

和我的DropDownList

<asp:DropDownList 
    ID="DropDownList2" 
    runat="server" 
    DataSourceID="sql_enabled_ddl" 
    DataTextField="description" 
    DataValueField="id_enabled" 
    SelectedValue='<%# Bind("id_enabled") %>' 
    Width="87%"> 
</asp:DropDownList>  

回答

0

你不需要綁定到的SelectedValue,除非你使用像GridView的這裏面的數據的控制。

刪除SelectedValue='<%# Bind("id_enabled") %>'

<asp:SqlDataSource 
    ID="sql_enabled_ddl" 
    runat="server" 
    ConnectionString="<%$ ConnectionStrings:Tip-Tour %>" 
    SelectCommand="SELECT 
       id_enabled, 
       description 

      FROM 
      (
       SELECT 
        1 AS id_enabled, 
        'true' AS description 

        UNION 

        SELECT 
        2 AS id_enabled, 
        'false' AS description 

      ) AS passport_enabled"></asp:SqlDataSource> 
<asp:DropDownList 
    ID="DropDownList2" 
    runat="server" 
    DataSourceID="sql_enabled_ddl" 
    DataTextField="description" 
    DataValueField="id_enabled" 
    Width="87%"> 
</asp:DropDownList> 
+0

tthat引發不同的錯誤....異常詳細信息:System.Data.SqlClient.SqlException:無效的列名稱'id_enabled'。 – blitzeus

+0

你能在測試新的aspx頁面上面的代碼中沒有母版頁? – Win

+0

這是一個FormView EditItemTemplate中 – blitzeus