2015-01-09 127 views
-5

我有一個下拉列表,必須展示從文件夾中的圖像文件的名稱,但是當我運行頁面此錯誤累積:編譯器錯誤信息:CS1061:

編譯器錯誤信息:CS1061:' ASP.pagesnew_managementpages_manageproducts_aspx'不包含'ddImage_SelectedIndexChanged'的定義,並且沒有找到接受類型爲'ASP.pagesnew_managementpages_manageproducts_aspx'的第一個參數的擴展方法'ddImage_SelectedIndexChanged'(您是否缺少using指令或程序集引用?)

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ManageProducts.aspx.cs" Inherits="PagesNew_ManagementPages_ManageProducts" %> 

那是錯誤的標籤:

Image:</p> 
Line 25:  <p> 
Line 26:   <asp:DropDownList ID="ddImage" runat="server" OnSelectedIndexChanged="ddImage_SelectedIndexChanged"> 
Line 27:   </asp:DropDownList> 
Line 28:  </p> 

這是整個文件:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
    <p> 
     Name:</p> 
    <p> 
     <asp:TextBox ID="txtName" runat="server"></asp:TextBox> 
    </p> 
    <p> 
     Type:</p> 
    <p> 
     <asp:DropDownList ID="ddType" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id"> 
     </asp:DropDownList> 
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [ProductTypes] ORDER BY [Name]"></asp:SqlDataSource> 
    </p> 
    <p> 
     Price:</p> 
    <p> 
     <asp:TextBox ID="txtPrice" runat="server"></asp:TextBox> 
    </p> 
    <p> 
     Image:</p> 
    <p> 
     <asp:DropDownList ID="ddImage" runat="server" OnSelectedIndexChanged="ddImage_SelectedIndexChanged"> 
     </asp:DropDownList> 
    </p> 
    <p> 
     Description:</p> 
    <p> 
     <asp:TextBox ID="txtDescription" runat="server" Height="72px" TextMode="MultiLine" Width="223px"></asp:TextBox> 
    </p> 
    <p> 
     <asp:Button ID="btnSubmit" runat="server" Text="Submit" /> 
    </p> 
    <p> 
     <asp:Label ID="lblResult" runat="server"></asp:Label> 
    </p> 
</asp:Content> 

我不明白什麼是錯?

+1

你曾經定義過'ddImage_SelectedIndexChanged'嗎? – 2015-01-09 21:29:53

+0

錯誤消息不能更清晰......如果您在aspx文件中引用事件處理程序,則必須在代碼隱藏中定義它。 – walther 2015-01-09 21:44:45

+0

是的,我只是在代碼隱藏中定義它,但我的圖像名稱是下拉列表中的項目沒有顯示在下拉列表中! – Shosho 2015-01-09 22:31:27

回答

0

是的,選擇下拉菜單,轉到它的屬性,點擊事件並雙擊它所表示的onSelectedindexChanged,VS將創建事件的定義並指引您的光標。

只要在裏面寫一個簡單的代碼行,看看它是否編譯。

如果您已經完成了這項工作,請在該事件上設置一個斷點,啓用從工具拋出的異常,然後運行事件,它應該給出更詳細的消息,告訴它爲什麼失敗。

+0

是的,我只是在代碼隱藏中定義它,但我的圖像名稱是下拉列表中的項目沒有顯示在下拉列表中! @約翰桑德斯輸出是空的下拉列表!哪裏不對? – Shosho 2015-01-09 22:42:25

+0

是的,我只是在代碼隱藏中定義它,但我的圖像名稱是下拉列表的項目不顯示在下拉列表中! @walther輸出是空的下拉列表!哪裏不對? – Shosho 2015-01-09 22:42:50

+0

是的,我只是在代碼隱藏中定義它,但我的圖像名稱是下拉列表的項目不顯示在下拉列表中! @YankTHEcode輸出是空的下拉列表!哪裏不對? – Shosho 2015-01-09 22:43:45