0
public class PrintHelper
    {
        public PrintHelper()
        {
        }

        public static void PrintWebControl(Control ctrl, string Header, string Date)
        {
            Label lblHeader = new Label();
            lblHeader.Text = "MSJ Bank Financial - " + Header + " (" + Date + ")<br/><hr/><br/>";

            PrintWebControl(ctrl, lblHeader, string.Empty);
        }

        //Print Method
        public static void PrintWebControl(Control ctrl, Label lblHeader, string Script)
        {
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            if (ctrl is WebControl)
            {
                Unit w = new Unit(100, UnitType.Percentage);
                ((WebControl)ctrl).Width = w;
            }
            Page pg = new Page();
            pg.EnableEventValidation = false;
            if (Script != string.Empty)
            {
                pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
            }
            HtmlForm frm = new HtmlForm();
            pg.Controls.Add(frm);
            frm.Attributes.Add("runat", "server");
            frm.Controls.Add(lblHeader);
            frm.Controls.Add(ctrl);
            pg.DesignerInitialize();
            pg.RenderControl(htmlWrite);

            string strHTML = stringWrite.ToString();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(strHTML);
            HttpContext.Current.Response.Write("<script>window.print();</script>");
            HttpContext.Current.Response.End();
        }
    }





        <div id="Report" runat="server">
            <asp:Repeater ID="rptView" runat="server" OnItemDataBound="rptView_ItemDataBound">
                <HeaderTemplate>
                    <table class="table">
                        <tr class="RepeaterHeader">
                            <th align="center">Date</th>
                            <th align="center">Amount</th>
                            <th align="center">Description</th>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr class="RepeaterData">
                        <td align="center"><%#Eval("Date", "{0:d}") %></td>
                        <td align="center"><%#Eval("Amount", "{0:C}")%></td>
                        <td align="center"><%#Eval("Description")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
            <br /><br />
            <table>
                <tr>
                    <td><asp:Label runat="server" Text="Grand Total Amount: " /></td>
                    <td><asp:Label ID="lblLoanAmt" runat="server" /></td>
                </tr>
            </table>
        </div>

In This Page, i pass the entire <div id="Report" runat="server">....</div> to the PrintHelp.cs
PrintHelp.PrintWebControl(Report, "Header", "12/01/2013");
And now note that my <div> tag has a repeater control which containing a table format, and the table has a class class="table"
now my problem is whenever i execuute this PrintHelp.PrintWebControl(Report, "Header", "12/01/2013"); statement, my repeater table format is gone, same as the class="table"
How can i pass the control with the class?

1
Contributor
1
Reply
13
Views
3 Years
Discussion Span
Last Post by gahhon
0
protected void PassControl(Control ctrl)
{
    Control newCtrl = new Control();
    newCtrol.Controls.Add(ctrl);
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.