views:

563

answers:

3

What am I doing wrong since the content in the < EditItemTemplate > is not displayed 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-behind:

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

In your function fwHotelDetails_ModeChanging, add this:

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
BenB
Thanks for your answer. I already have this in my code behind.
Steven
A: 

Remove this line below, its not needed:

 fwHotelDetails.ChangeMode(FormViewMode.Edit);

Example can be seen here for using the EditTemplate.

rick schott
Removing that line doesn't change anything. The link doesn't really help much.
Steven
I have made demo project with your code and a different datasource and it works fine with my suggestion. Can you post the rest of your code? Something must be interfering.
rick schott
I've added the rest of the code behind
Steven
A: 

Ok have you tried putting a breakpoint on fwHotelDetails_ModeChanging and then debugging the App? Does the breakpoint get hit when you click the edit button.

At least this will tell you where your problem lies. That is [1] the events are not hooked up correctly or [2] there is something going wrong with ChangeMode.

I realise this isnt a solution but if you tell me whether the breakpoint hits i can help you further.

Kaius
I'm using the free version of Visual Studio 2008 - and I can't get the debugging working on it :(
Steven
What happens when you try to debug? You should be able to debug it using the free version. Ok if for some reason you cannot get the debugger to work you could put a "tracer bullet" in the code. This is something that will tell you that the method executed. How about putting Response.Redirect("google.com"); in the fwHotelDetails_ModeChanging method. At least then you will know if that method is firing as you will get redirected from your page to google. In any case i would recommend getting the debugger working as a priority over this as it will save you time in the long run.
Kaius