Click here to Skip to main content
16,017,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the DataBound code shown below, when fvWriteUp.PageCount and fvWriteUp.DataItem both = 1, why is fvWriteUp.BottomPagerRow null when there is only one record on the page?
C#
protected void fvWriteUp_DataBound(object sender, EventArgs e)
{
    int totalPages = fvWriteUp.PageCount;
    int itemCount = fvWriteUp.DataItemCount;

    // Get the pager row. From MS FormView.BottomPagerRow Property
    FormViewRow pagerRow = fvWriteUp.BottomPagerRow;

    // Get the Label controls that display the current page information 
    // from the pager row.

    Label pageNum = (Label)pagerRow.Cells[0].FindControl("PageNumberLabel");
    Label totalNum = (Label)pagerRow.Cells[0].FindControl("TotalPagesLabel");

    if ((pageNum != null) && (totalNum != null))
    {
        // Update the Label controls with the current page values.
        int page = fvWriteUp.PageIndex + 1;
        int count = fvWriteUp.PageCount;
        pageNum.Text = page.ToString();
        totalNum.Text = count.ToString();
     }
}

ASP.NET
<PagerTemplate>
    <asp:Table CssClass="fvFooter" ID="RecordNav" runat="server">
        <asp:TableRow
             ID="TableRow4"
             runat="server">
             <asp:TableCell CssClass="recNav">
             <asp:Button ID="btnFirst" CssClass="btn btnRecNav" CommandName="Page" CommandArgument="First" Text="First" runat="server" />
             <asp:Button ID="btnPrevious" CssClass="btn btnRecNav" CommandName="Page" CommandArgument="Prev" Text="Previous" runat="server" />
             <asp:Button ID="btnNext" CssClass="btn btnRecNav" CommandName="Page" CommandArgument="Next" Text="Next" runat="server" />
             <asp:Button ID="btnLast" CssClass="btn btnRecNav" CommandName="Page" CommandArgument="Last" Text="Last" runat="server" />
            </asp:TableCell><asp:TableCell CssClass="recCounter">
            <asp:Label CssClass="lblRecs" ID="lblRecs1" runat="server" Text="Record"></asp:Label>
            <asp:Label CssClass="lblRecCount" ID="PageNumberLabel" runat="server"></asp:Label>
            <asp:Label CssClass="lblRecs" ID="lblRecs2" runat="server" Text="of"></asp:Label>
<asp:Label CssClass="lblRecCount" ID="TotalPagesLabel" runat="server"></asp:Label>                                                                                      </asp:TableCell><asp:TableCell></asp:TableCell></asp:TableRow></asp:Table>
</PagerTemplate>
<PagerSettings FirstPageText="First" LastPageText="Last" Mode="NextPreviousFirstLast"                 NextPageText="Next" PreviousPageText="Previous" Position="Bottom" />


What I have tried:

I’ve tried code like this in PreRender without luck

protected void fvWriteUp_PreRender(object sender, EventArgs e)
{
    FormViewRow pagerRow = fvWriteUp.BottomPagerRow;
    if (pagerRow != null && pagerRow.Visible == false)
    {
        pagerRow.Visible = true;
        fvWriteUp.BottomPagerRow.Visible = true;
    }

}
Posted
Comments
Richard MacCutchan 30-Oct-17 19:07pm    
Where does fvWriteUp.BottomPagerRow; get set to a value?
Member 13494479 1-Nov-17 19:49pm    
Apologies for delayed response. Have had this question on various forums w/o response so have all but given up.
This webpage is being opened via a Menu on a master page thru a Response.Redirect. The code on this page that you might be asking about is
protected void fvWriteUp_PreRender(object sender, EventArgs e)
{
FormViewRow pagerRow = fvWriteUp.BottomPagerRow;
if (pagerRow != null && pagerRow.Visible == false)
{
pagerRow.Visible = true;
fvWriteUp.BottomPagerRow.Visible = true;
}
}
protected void Page_Init(object sender, EventArgs e)
{
//Call FindButton_Click:
Response.Write("page_init ");
Master.FindButton.Click += new EventHandler(FindButton_Click);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Menu: use session vars from previous form to set datasource
Response.Write("page_load ");
string ClientFileCode = (string)(Session["sesClientFileCode"]);
string WOJob = (string)(Session["sesWOJob"]);
SqlDataSource1.SelectParameters["txtClientFileCode"].DefaultValue = ClientFileCode;
SqlDataSource1.SelectParameters["txtWOJob"].DefaultValue = Convert.ToString(WOJob);
fvWriteUp.DataSource = SqlDataSource1;
SqlDataSource1.DataBind();
fvWriteUp.DataBind();
}
}
protected void fvWriteUp_ItemCreated(object sender, EventArgs e)
{
// Use the Row property to retrieve the data row from
// the FormView control.
FormViewRow row = fvWriteUp.Row;

// Get the data item bound to the FormView control.
DataRowView rowView = (DataRowView)fvWriteUp.DataItem;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900