开发者

EditItem in ListView - doesn't load edit template

Howdy, I don't know if it is a known issue - but when I click on the Edit button once - the server reloads the listview - when I click on the edit button once again I receive the EditTemplate and I'm able to edit the list view ... is this is a known behaviour?

Furthermore: The c# behind is working through the full editing cycle ( loads the special editing data ) - but I still only see the usual "view".

//Added some meat to the question

public void test_ItemEditing(Object sender, ListViewEditEventArgs e)
{
    // returns the curren开发者_JS百科t key
    DataKey currentDataKey = speiseplanListView.DataKeys[e.NewEditIndex];

    // fetches the information - for the whole plane
    DataTable speiseplan = getSpeiseplan(0);
    DataTable preisgruppen = getPreisgruppen();

    extractTags(speiseplan);
    extractPreise(speiseplan, preisgruppen);
    speiseplanListView.DataSource = speiseplan;
    speiseplanListView.DataBind();
}

This is the edit function - which gets called once the user presses the "edit" button --- it's completed on both tries .. however only the second try returns the "EditItemTemplate".

The page_load function is rather unnecessary for the edit event - since the edit event is a postback event - so the page load gets skipped in both cases.

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["USERID"] == null)
    {
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
        Session.Abandon();
    }
    else
    {
        this.kantinenID = Convert.ToInt32(Request["id"]);
        this.userID = Convert.ToInt16(Session["USERID"]);
        if (IsPostBack == false)
        {
            try
            {
                switch (Request["action"])
                {
                     ...                  
                }
            }
            catch (System.FormatException ex)
            {
              ...
            }
        }
    }
}


Add this to the start of your ItemEditing handler:

speiseplanListView.EditIndex = e.NewEditIndex;

Also, verify that speiseplanListView.DataBind(); is not being called upon postback in your page load handler.

Finally, this tutorial may be of some value to you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜