C# .NET - how page number in generating html report in C# dynamically from code behind

Asked By VIDYA on 11-Dec-13 02:52 AM
   strHtml.Append("<table style='width: 100%; margin-top: " + strtopmargin + " margin-bottom: " + strbottommargin + "; margin-left: 0; margin-right: 0;'>") 'OuterMost Table starts Here
        strHtml.Append("<tr>")
        strHtml.Append("<td>")

        strHtml.Append("<table style='width: 97%;  margin-top:0px; border-color: Blue; margin-left:2%; margin-right: 1%;'>") 'Inner Table 1 Starts here
        strHtml.Append("<tr>")
        strHtml.Append("<td>")

        strHtml.Append("<table width='100%'>") 'Inner Table 2 Starts here

        ''Printing Page Header
        strHtml.Append("<tr style='text-align: center;'><td colspan='5'>")
        strHtml.Append("<span style='font-size:" + strHeader1 + " font-weight: bold;'>Indus Healthplus Pvt. Ltd.</span></td></tr>")

        ''Printing Report Header
        If HeadingMode = "P" Then
            RepTitle = "Pending Kit Devlivery."
        ElseIf HeadingMode = "D" Then
            RepTitle = "Kit Devlivery."
        End If
        ''Printing Page subHeading
        strHtml.Append("<tr style='text-align: center;'><td colspan='5'>")
        strHtml.Append("<span style='font-size:" + strHeader3 + " font-weight: bold;'>" + RepTitle + "</span></td></tr>")

        ''Page Number
        strHtml.Append("<tr>")
        strHtml.Append("<td style='text-align: right;' colspan='5'><span style='font-size:" + strRepContent + " font-weight: bold; width: 10px;'>Page No :</span></td>")
        strHtml.Append("<td style='font-size: " + strRepContent + ";'>1</td>")
        strHtml.Append("</tr>")

        If dsMemberList.Tables.Count > 0 Then
            For Each dt As DataTable In dsMemberList.Tables

                strHtml.Append("<tr style='text-align: left;'>")
                strHtml.Append("<td colspan='5' style='font-size: " + strRepContent + ";width:1%;'><strong>Join Date from  " + dateFrom.ToString() + "  To  " + dateTo.ToString() + " </strong>")
                strHtml.Append(" </td>")
                strHtml.Append("</tr>")

                strHtml.Append("<tr style='text-align: left;'>")
                strHtml.Append("<td colspan='5' style='border-bottom-style: solid; border-bottom-color: #000000; border-bottom-width: 5px;width: 15%'>")
                strHtml.Append(" </td>")
                strHtml.Append("</tr>")

                strHtml.Append("<tr style='text-align: center;'>")
                strHtml.Append("<td style='font-size: " + strRepContent + ";width:1%;'><strong>Sr.No.</strong>")
                strHtml.Append("</td>")

                strHtml.Append("<td style='font-size: " + strRepContent + ";width:15%;'><strong>Join Date</strong>")
                strHtml.Append("</td>")

                strHtml.Append("<td style='font-size: " + strRepContent + ";width:15%;'><strong>Joining Amount</strong>")
                strHtml.Append("</td>")

                strHtml.Append("<td style='font-size: " + strRepContent + ";width:15%;'><strong>Member ID</strong>")
                strHtml.Append("</td>")

                strHtml.Append("<td style='font-size: " + strRepContent + ";width:25%;'><strong>Name</strong>")
                strHtml.Append("</td>")
                strHtml.Append("</tr>")

                strHtml.Append("<tr style='text-align: left;'>")
                strHtml.Append("<td style='font-size: " + strRepContent + ";width:10%;'><strong></strong>")
                strHtml.Append("</td>")
                strHtml.Append("</tr>")

                strHtml.Append("<tr style='text-align: left;'>")
                strHtml.Append("<td colspan='5' style='border-top-style: solid; border-top-color: #000000; border-bottom-width: 1px;width: 15%'>")
                strHtml.Append(" </td>")
                strHtml.Append("</tr>")
                Dim i As Integer = 0
                For Each row As DataRow In dt.Rows
                    i = i + 1
                    strHtml.Append("<tr style='text-align: center;'>")
                    strHtml.Append("<td style='font-size: " + strRepContent + ";width:1%;'>" + i.ToString() + "")
                    strHtml.Append("</td>")

                    strHtml.Append("<td style='font-size: " + strRepContent + ";width:15%;'>" + row.Item("JOIN_DATE").ToString() + "")
                    strHtml.Append("</td>")
                    'String.Format("Fixed formatted: {0:n3}", iNbr)
                    strHtml.Append("<td style='font-size: " + strRepContent + ";width:15%;'>" + String.Format("{0:n3}", row.Item("AMT_PAID").ToString()) + "")
                    strHtml.Append("</td>")

                    strHtml.Append("<td style='font-size: " + strRepContent + ";width:15%;'>" + row.Item("MEMBER_ID").ToString() + "")
                    strHtml.Append("</td>")

                    strHtml.Append("<td style='font-size: " + strRepContent + ";width:25%;'>" + row.Item("FiRM_NAME").ToString() + "")
                    strHtml.Append("</td>")
                    strHtml.Append("</tr>")
                    strHtml.Append("<tr style='text-align: left;'>")
                    strHtml.Append("<td colspan='5' >")
                    strHtml.Append(" </td>")
                    strHtml.Append("</tr>")
                Next
            Next
            strHtml.Append("</table>") 'Inner Table 3 closed here
        End If
        strHtml.Append("</tbody>")
        strHtml.Append("</table>") 'Inner Table 2 closed here

        strHtml.Append("</td>")
        strHtml.Append("</tr>")
        strHtml.Append("</table>") 'Inner Table 1 closed here

        strHtml.Append("</td>")
        strHtml.Append("</tr>")


        strHtml.Append("</table>") 'OuterMost Table closed Here

Robbe Morris replied to VIDYA on 11-Dec-13 10:47 AM
If you do not want to use an actual printer to automatically put this on the printed page for you, you don't have any choice but to manually count lines you will allow per page before you implement a CSS page-break-after.  Then, write that into the html as the last line on the page.