2009-09-23 46 views
2

我在做什麼錯誤,因爲當點擊編輯按鈕時,< EditItemTemplate>中的內容未顯示?無法在FormView中的<EditItemTemplate>中顯示內容

<asp:FormView runat="server" id="fwHotelDetails" DataKeyNames="id" OnDataBound="fwHotelDetails_DataBound" OnModeChanging="fwHotelDetails_ModeChanging"> 

    <ItemTemplate> 
    //display content here 
    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" /> 
    </ItemTemplate> 

    <EditItemTemplate> 
    This text should be displayed when I click the Edit button 
    <asp:LinkButton runat="server" ID="UpDateButton" CausesValidation="false" CommandName="Update" Text="Lagre" /> 
    </EditItemTemplate>    

</asp:FormView> 

更新

這是我的代碼隱藏:

namespace development.templates 
{ 
    public partial class HotelDetails : TemplatePage 
    { 
     static Hotel hotel; 
     protected DataRow drHotel; 
     DataTable dtCriteria; 
     DataTable dtHotel; 
     private HotelCriteria hotelCriteria; 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      int hotelID = Convert.ToInt32(Request.QueryString["hotelid"].ToString()); 

      if (!IsPostBack) 
      { 
       if (hotelID != 0) 
       { 
        // Create Hotel instance based on hoteID. 
        hotel = new Hotel(hotelID); 
        drHotel = hotel.hotelData.Rows[0]; 
        dtHotel = hotel.getHotelsByCity(drHotel["city"].ToString()); 


        // Hotel scrore is calculated from a score which is derived from certain criterias. 
        hotelCriteria = new HotelCriteria(hotelID); 
        dtCriteria = hotelCriteria.getHotelCriteria(); 

        //Set datasource for hotel list in right sidebar. 
        hotelListByCity.DataSource = correctList(dtHotel, hotelID); 
        hotelListByCity.DataBind(); 

        // Set datasource for current hotel 
        fwHotelDetails.DataSource = hotel.hotelData; 
        fwHotelDetails.DataBind(); 

       } 
      } 
     } 



     protected void fwHotelDetails_DataBound(object sender, EventArgs e) 
     { 
      //Find the criteria list and set the datasource 
      Repeater rep = (Repeater)fwHotelDetails.FindControl("repCriteriaScore"); 

      rep.DataSource = this.dtCriteria; 
      rep.DataBind(); 

      // Controll is user is logged in. If logged in, then user may add, edit or delete hotel record. 
      System.Security.Principal.IPrincipal user = Context.User; 
      if ((user != null) && user.Identity.IsAuthenticated){ 
       Panel panel = (Panel)fwHotelDetails.FindControl("administrationPanel"); 
       panel.Visible = true; 
      } 
     } 


     protected void fwHotelDetails_ModeChanging(object sender, FormViewModeEventArgs e) 
     { 
      switch (e.NewMode) 
      { 
       case FormViewMode.Edit: 
        MessageLabel.Text = "Edit mode"; 
        fwHotelDetails.ChangeMode(FormViewMode.Edit); 
        break; 
       case FormViewMode.ReadOnly: 
        MessageLabel.Text = "Read mode"; 
        break; 
       case FormViewMode.Insert: 
        MessageLabel.Text = "Insert mode"; 
        break; 
      } 
     } 
    } 
} 
+0

任何理由酒店是靜態的嗎? – 2009-09-24 18:43:30

+0

因爲Visual Studio這麼說? :op – Steven 2009-09-24 21:05:13

回答

0

在你的函數fwHotelDetails_ModeChanging,補充一點:

fwHotelDetails.ChangeMode(FormViewMode.Edit) 

Protected Sub fwHotelDetails_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewModeEventArgs) Handles fwHotelDetails.ModeChanging 
     fwHotelDetails.ChangeMode(FormViewMode.Edit) 
    End Sub 
+0

感謝您的回答。我已經在我的代碼背後有這個了。 – Steven 2009-09-23 11:40:17

0

好吧,你有沒有嘗試在fwHotelDetails_ModeChanging上放置斷點,然後調試應用程序?單擊編輯按鈕時是否觸發斷點?

至少這會告訴你你的問題在哪裏。那是[1]事件沒有正確連接,或者[2] ChangeMode有問題。

我意識到這不是一個解決方案,但如果你告訴我斷點是否可以幫助你進一步。

+0

我使用的是Visual Studio 2008的免費版本 - 我無法獲得調試工作:( – Steven 2009-09-24 21:07:16

+0

當您嘗試調試時會發生什麼?您應該可以使用免費版本進行調試。由於某些原因你不能讓調試器工作,你可以在代碼中加入一個「tracer bullet」,這會告訴你方法被執行了,如何把response.Redirect(「google.com」)放在fwHotelDetails_ModeChanging方法,至少可以知道該方法是否正在觸發,因爲您將從您的頁面重定向到Google,無論如何,我建議讓調試器作爲優先級工作,因爲這樣可以節省您長期的時間。 – SecretDeveloper 2009-09-25 08:03:18

1

如果記錄爲空,EditItemTemplate也不會顯示。換句話說,如果你有一個gridview,你從中選擇了一個細節記錄,並且它們沒有選擇網格項目的詳細信息,那麼表單根本就不會顯示出來。我檢查是否詳細記錄爲空,如果是,我將formview或detailsview設置爲「插入」模式。所以他們可以輸入新的記錄。