Unable to display content in <EditItemTemplate> in FormView

What am I doing wrong since the content in <EditItemTemplate> is not showing when I click the Edit button?

<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>

      

Update

This is my code:

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;
            }
        }
    }
}

      

+2


source to share


3 answers


The EditItemTemplate will also not show if the entry is empty. In other words, if you have a gridview that you select a detail entry from what the formview feeds, and there is no detail for the selected grid item, the form won't render at all. I check if the data record is null and if so I set the formview or detailsview mode to "insert" mode. so they can enter a new entry.



+1


source


In your fwHotelDetails_ModeChanging function add the following:

fwHotelDetails.ChangeMode(FormViewMode.Edit)

      



i.e.

    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


source


Okay, have you tried putting a breakpoint on fwHotelDetails_ModeChanging and then debugging the application? Whether the breakpoint is removed when the edit button is pressed.

At least this will tell you where your problem is. This is [1], the events are not connected correctly, or [2] there is something wrong with ChangeMode.

I realize this is not a solution, but if you tell me if the breakpoint will succeed, I can help you.

0


source







All Articles