开发者

Editing an item in a ListView does not occur if item is on any page, but the first?

I have an asp:ListView control which list playlists. It has paging supported and holds 10 playlists per page. Currently, when the user clicks a view link under a playlist, it redirects them to another page where they can view the songs in the playlist. If they want to edit the songs in the playlist, 开发者_如何学编程they can click an edit link and it will redirect them back to the the page with the playlists and it will display a panel with the songs in the list they can add and remove. This works fine if the item they are editing is on the first page, but if the item is not on the first page, the item that gets market for editing is the first item on the first page, so I guess my question is, how do I get to the page of the ListView that the item is on. Currently in my Page Load, I have the following:

if (!Page.IsPostBack)
{
    LoadPlaylists();

    if(Request.QueryString["edit"] != null)
    {
        ListViewEditEventArgs args = new 
        ListViewEditEventArgs(FindEditItemIndex(Request.QueryString["edit"]));

        lvwPortfolios_RowEditing(this.lvwPlaylists, args);
    }
 }

I am using a DataPager control to handle the paging.

This is where it gets it query string from:

protected void lnkEditPlaylist_Click(object sender, EventArgs e)
{
    Response.Redirect("~/playlist/playlist.aspx?edit=" + lblPlaylistName.Text.Trim());
}

Interesting thing to note is that I believe it puts the correct item in edit mode, but it does not jump to the correct page, it stays on the first page of the listview, so it looks like it is an issue with the datapager control. Is it just as simple as programmatically jumping to the correct page?


Did you try changing your page load to this:

if (!Page.IsPostBack)
{
    LoadPlaylists();
}

if(Request.QueryString["edit"] != null)
{
    ListViewEditEventArgs args = new 
    ListViewEditEventArgs(FindEditItemIndex(Request.QueryString["edit"]));

    lvwPortfolios_RowEditing(this.lvwPlaylists, args);
}

Here you take the editing out of the check for a post back. I feel like this could be your problem because editing is only allowed when the page is first loaded the way you have it now.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜