33319

FormView not displaying PagerTemplate when only 1 item in DataSource

I have a FormView control with a custom PagerTemplate with my own paging LinkButtons. All works great until the dataset that I load only contains one record/item and hides the PagerTemplate completely. I've searched online and found several answers to simply add:

protected void fvAppHMDA_PreRender(object sender, EventArgs e) { if (fvAppHMDA.TopPagerRow != null) fvAppHMDA.TopPagerRow.Visible = true; }

However, this is not making one bit of difference. It seems that when there is only one record in the data set, the FormView.TopPagerRow is always null. It seems that there needs to be a way to intercept this but I've tried doing it in both OnPreRender and OnDataBound events but still no dice.

Below is sample of my code if that helps:

<strong>ASPX</strong>

<asp:FormView ID="fvAppHMDA" runat="server" AllowPaging="True" DefaultMode="Edit" DataSourceID="dsLoanApplication" Width="100%" onpageindexchanging="fvAppHMDA_PageIndexChanging" OnDataBound="fvAppHMDA_DataBound" OnPageIndexChanged="fvAppHMDA_PageIndexChanged" OnItemCreated="fvAppHMDA_ItemCreated" DataKeyNames="ApplicationID" OnPreRender="fvAppHMDA_PreRender"> <PagerTemplate> <div class="tab_toolbar"> <asp:LinkButton ID="lnkMoveFirst" runat="server" ToolTip="Move to the First Application" CommandName="Page" CommandArgument="First"><img src="images/icons/Icon_ArrowBackEnd.png" width="16" height="16" class="grid2" alt="Move to the First Application" /></asp:LinkButton> <asp:LinkButton ID="lnkMovePrevPage" runat="server" ToolTip="Move to the Previous Page" CommandName="Page" onclick="lnkMovePrevPage_Click" Enabled="False"><img src="images/icons/Icon_ArrowBackSkip.png" width="16" height="16" class="grid2" alt="Move to the Previous Page" /></asp:LinkButton> <asp:LinkButton ID="lnkMovePrevApp" runat="server" ToolTip="Move to the Previous Application" CommandName="Page" CommandArgument="Prev"><img src="images/icons/Icon_ArrowBack.png" width="16" height="16" class="grid2" alt="Move to the Previous Application" /></asp:LinkButton> <div class="grid2_container"><asp:TextBox ID="txtMoveNumber" runat="server" Text="0" Columns="5"></asp:TextBox> of <asp:Label ID="lblMoveTotal" runat="server" Text="0"></asp:Label></div> <asp:LinkButton ID="lnkMoveNextApp" runat="server" ToolTip="Move to the Next Application" CommandName="Page" CommandArgument="Next"><img src="images/icons/Icon_ArrowForward.png" width="16" height="16" class="grid2" alt="Move to the Next Application" /></asp:LinkButton> <asp:LinkButton ID="lnkMoveNextPage" runat="server" ToolTip="Move to the Next Page" CommandName="Page" onclick="lnkMoveNextPage_Click" Enabled="False"><img src="images/icons/Icon_ArrowForwardSkip.png" width="16" height="16" class="grid2" alt="Move to the Next Page" /></asp:LinkButton> <asp:LinkButton ID="lnkMoveLast" runat="server" ToolTip="Move to the Last Application" CommandName="Page" CommandArgument="Last"><img src="images/icons/Icon_ArrowForwardEnd.png" width="16" height="16" class="grid2" alt="Move to the Last Application" /></asp:LinkButton> </div> </PagerTemplate> <PagerSettings Mode="NextPreviousFirstLast" Position="Top" /> <EditItemTemplate> <!-- FORM CONTROLS HERE --> </EditItemTemplate>

<strong>Codebehind</strong>

protected void fvAppHMDA_PreRender(object sender, EventArgs e) { if (fvAppHMDA.TopPagerRow != null) fvAppHMDA.TopPagerRow.Visible = true; } protected void fvAppHMDA_DataBound(object sender, EventArgs e) { if (fvAppHMDA.DataItemCount != 0) { // Update Current and Total Page ((Label)fvAppHMDA.TopPagerRow.FindControl("lblMoveTotal")).Text = fvAppHMDA.PageCount.ToString(); ((TextBox)fvAppHMDA.TopPagerRow.FindControl("txtMoveNumber")).Text = (fvAppHMDA.PageIndex + 1).ToString(); // Enable/Disable Page buttons based on Current Page if (fvAppHMDA.PageIndex + 1 == fvAppHMDA.PageCount) { ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveLast")).Enabled = false; ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveNextApp")).Enabled = false; } else if (fvAppHMDA.PageIndex == 0) { ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveFirst")).Enabled = false; ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMovePrevApp")).Enabled = false; } if (fvAppHMDA.PageIndex + 10 <= fvAppHMDA.PageCount - 1) { ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveNextPage")).Enabled = true; } if (fvAppHMDA.PageIndex - 10 > -1) { ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMovePrevPage")).Enabled = true; } fvAppHMDA.TopPagerRow.Cells[0].Visible = true; } if (fvAppHMDA.TopPagerRow != null) fvAppHMDA.TopPagerRow.Visible = true; }

thanks!

Answer1:

Tried this http://forums.asp.net/t/1016811.aspx/1 and it worked fine for me. If you want a top pager row, I guess HeaderTemplate would also work.

"In the markup for the FormView I set:

AllowPaging="true"

PagerSettings-Visible="false"

Then I put all of my controls for paging in the FooterTemplate of the FormView. By doing it this way I was still able to handle all of the paging events and always have the "Pager Row" visible even when there was only one record being returned in the datasource."

Recommend

  • Can't access Subitems in ListView while looping
  • How to create a dynamic hyperlink in datalist
  • Hyperlink a column with relative path value of another column in mysql database
  • Display youtube video using link from database
  • ASP.NET VB Nested Listviews
  • id key not showing up in listview
  • How can I prevent appendChild() from adding the xmlns=“”
  • asp.net gridview sorting custom datasource
  • Add image using itextsharp
  • ObjectDataSource could not find a non-generic method that has parameters when using update and delet
  • How To Insert USERID (Type: Raw, Size: 16) from Ora_aspnet_users to Another Table
  • got anyway i set class inside repeater datarow find by data ID when do postback?
  • How to change Repeater DataSourceID?
  • Export Error to Excel Gridview Column with Textbox
  • RadioButtonList inside Repeater bound to XmlDataSource
  • Dynamic buttons in GridView - Button.Click event not firing
  • Hide ListView column in visual studio 2010 C#
  • An exception of type 'System.OutOfMemoryException'
  • ASP.Net GridView UpdatePanel Paging Gives Error On Second Click
  • How do I declaratively bind 'SelectedValue' to datasource field?
  • How do I add rounded corners to a GridView table in my .net code?
  • Clicking checkbox causes onCheckedChanged to fire twice
  • The name 'control' does not exist in the current context
  • FormView not displaying PagerTemplate when only 1 item in DataSource
  • Set GridView Value ItemStyle ForeColor based on Row/Column Value
  • Getting error when retrieve contacts from Exact Online
  • Reuse code from website project in my web application project
  • Set current date in formview
  • Android full screen on only one activity?
  • Django: Count of Group Elements
  • Fetching methods from BroadcastReceiver to update UI
  • Symfony2: How to get request parameter
  • GridView Sorting works once only
  • WPF Applying a trigger on binding failure
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?