views:

159

answers:

1

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?

A: 

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.

ryanulit
I will try this, but I am a little confused. Isn't the page being loaded when I go from one page to another? Example, I view the songs in the playlist on one.aspx and when I click on an edit link on one.aspx, it redirects me to two.aspx, so isn't two.aspx loading for the first time. Could this have more to do with the datapager, because when I click edit, it defaults to the first item on the page, but the actual item that is intended for editing, let say it is on the second page, is put in edit mode too.
Xaisoft
Well I was slightly confused to begin with. I assume that the datapager control does not actually move to a new .aspx page and just tracks what page of playlist data it is on through viewstate, therefore the page is being refreshed everytime you page your data, so after the initial page load, every refresh would be a postback. And since your edit panel is on the same page, it wouldn't run through that if block checking the querystring parameter.
ryanulit
But if I am coming from another page, it would run through the if block, right?
Xaisoft
The code within the IF (!Page.IsPostBack) block will only run the first time the page is loaded, so yes it would if you are coming from another page. That was one reason I asked to see your html so I could see the path the links take.
ryanulit