views:

413

answers:

1

Hi,

I have a datapager with a pagertemplate. In the template I have a "Show All" button, which sets the PageSize of the datapager to show all records. This works fine but I want to be able to hide the button when it's clicked. It's in an UpdatePanel so I don't know if that makes a difference?

       <asp:DataPager ID="Pager" runat="server" PagedControlID="rangeList" PageSize="15" EnableViewState="false">                       
    <Fields>
     <asp:TemplatePagerField>
      <PagerTemplate>
       <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="<%# Container.TotalRowCount.ToString() %>"
        oncommand="LinkButton1_Command" >Show All Ranges</asp:LinkButton>&nbsp;&nbsp;
      </PagerTemplate>
     </asp:TemplatePagerField>
     <asp:numericpagerfield ButtonCount="10" NextPageText="..." PreviousPageText="..." CurrentPageLabelCssClass="pageOn" />
    </Fields>        
   </asp:DataPager>

And the codebehind:

 protected void LinkButton1_Command(object sender, CommandEventArgs e)

{ this.Pager.PageSize = int.Parse(e.CommandArgument.ToString());

LinkButton lb = (LinkButton)sender; if (lb != null) { lb.Visible = false; }

rangeList.DataBind(); }

The first click works fine, and refreshes the ListView which in turn adjusts the pager to show one page with all the results on it, but the button doesn't disappear as I want it to.

Any ideas?

A: 

If there's nothing to display within the pager, why not hide the Pager control itself:

protected void LinkButton1_Command(object sender, CommandEventArgs e)
{ 
    this.Pager.PageSize = int.Parse(e.CommandArgument.ToString());
    this.Pager.Visible = false; 
    lnkShowPages.Visible = true; // EDIT only
    rangeList.DataBind(); 
}

EDIT:

You could have a second "Show Pages" LinkButton that's initially not visible and becomes visible when the Show All LinkButton is clicked (above). When this new LinkButton is clicked, it could then enable paging by setting the Pager's PageSize and visibility and hiding itself:

protected void lnkShowPages_Command(object sender, CommandEventArgs e)
{ 
    this.Pager.PageSize = int.Parse(e.CommandArgument.ToString());
    this.Pager.Visible = true; 
    lnkShowPages.Visible = false; 
    rangeList.DataBind(); 
}
CAbbott
You, sir, have just pointed out the most obvious thing which I completely missed... Thanks
Dave