2009-09-23 44 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设置为“插入”模式。所以他们可以输入新的记录。