[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

print listview

I have 9 cold listview that I wanted to print.This is asp.net app not windows.how is that done?
0
zachvaldez
Asked:
zachvaldez
  • 13
  • 10
1 Solution
 
Jini Jose.Net Team LeadCommented:
add an invisible iframe to the page. then on the listview page add a button to print. add javascript code to add the listview source to the iframe. then do print the iframe.
0
 
zachvaldezAuthor Commented:
Do you have sample code?thanks
0
 
Jini Jose.Net Team LeadCommented:
the print button click javascript

function Button1_onclick() {

var contentctrl=document.getElementById('listviewDiv');
var oIframe = document.getElementById('ifrmPrint');
var oContent = contentctrl.innerHTML;

var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<html><head>");
oDoc.write("</head><body onload='this.focus(); this.print();'>");
oDoc.write("<table>"+ oContent + "</table></body></html>");
oDoc.close();

return false;
}


iframe

<iframe id="ifrmPrint" src="#" style="width: 0px; height: 0px; visibility: hidden;"></iframe>

now add a div/table and place the listview inside that
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
zachvaldezAuthor Commented:
>>>add an invisible iframe to the page. then on the listview page add a button to print. add javascript code to add the listview source to the iframe. then do print the iframe

are there 2 pages here.

I have a thank you page whre Id like to display and print the listview
0
 
zachvaldezAuthor Commented:
btw, where will I find the iframe control to add in the aspx page?
0
 
Jini Jose.Net Team LeadCommented:
<iframe id="ifrmPrint" src="#" style="width: 0px; height: 0px; visibility: hidden;"></iframe>

add this..
0
 
zachvaldezAuthor Commented:
Well my question is i can't find the control in toolbox.
0
 
Jini Jose.Net Team LeadCommented:
iframe is not a control. so it will not be in your control box
0
 
zachvaldezAuthor Commented:
how do I execute the button_click javascript?
0
 
Jini Jose.Net Team LeadCommented:
you have to place a html button and its onclick event call the Button1_onclick event
0
 
zachvaldezAuthor Commented:
not a server side button(asp.net conteol?)
also the listview is not displayed becaiuse it it under the iframe.
0
 
Jini Jose.Net Team LeadCommented:
dont place the list view or any other inside the iframe.
0
 
zachvaldezAuthor Commented:
iframe will be by itself?
0
 
zachvaldezAuthor Commented:
Ok,it works,however the print button icon is printed as well because it is inside the form. is there a way to avoid to display when printing?
0
 
Jini Jose.Net Team LeadCommented:
change the print button location to outside the listviewDiv
0
 
zachvaldezAuthor Commented:
i placed outside the div section
but is included when it prints
0
 
Jini Jose.Net Team LeadCommented:
no chance.
the button print function takes only the contents of listviewDiv.
0
 
zachvaldezAuthor Commented:
this is how I call the funciton; and I still get the print icon printed

function clickit(object) {

        var contentctrl = document.getElementById('listviewDiv');
        var oIframe = document.getElementById('ifrmPrint');
        var oContent = contentctrl.innerHTML;

        var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
        if (oDoc.document) oDoc = oDoc.document;
        oDoc.write("<html><head>");
        oDoc.write("</head><body onload='this.focus(); this.print();'>");
        oDoc.write("<table>" + oContent + "</table></body></html>");
        oDoc.close();

        return false;
    }


        <asp:Button ID="Button1" runat="server" Text="Print" OnClientClick="clickit(listviewDiv)" />
0
 
Jini Jose.Net Team LeadCommented:
can you please post your listviewDiv portion ?
0
 
zachvaldezAuthor Commented:
<iframe id="ifrmPrint" src="#" style="width: 0px; height: 0px; visibility: hidden;">
    </iframe>
    <div id='listviewDiv'>          


 <asp:ListView ID="ListView1" runat="server" DataKeyNames="G_ID" Style="margin-left: 0px">
                <LayoutTemplate>
                    <table cellpadding="1" border="1" runat="server" id="tblNames">
                        <tr id="Tr1" runat="server">
                            <th id="Th2" runat="server">
                                Last Name
                            </th>
                            <th id="Th3" runat="server">
                                First Name
                            </th>
                            <th id="Th4" runat="server">
                                1st Choice A
                            </th>
                            <th id="Th5" runat="server">
                                1st Choice B
                            </th>
                            <th id="Th6" runat="server">
                                1st Choice C
                            </th>

                        </tr>
                        <tr runat="server" id="itemPlaceholder" />
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr id="Tr2" runat="server" style="background-color: #FFFBD6; color: #333333;">
                        <td>
                            <asp:Label ID="LastNameLabel" runat="Server" CssClass="cap" Text='<%#Eval("PL_LNAME") %>' />
                        </td>
                        <td valign="top">
                            <asp:Label ID="FirstNameLabel" runat="Server" CssClass="cap" Text='<%#Eval("PL_FNAME") %>' />
                        </td>
                        <td valign="top">
                            <asp:Label ID="lblfirstchoiceA" runat="Server" Text='<%#Eval("FIRSTC_A") %>' />
                        </td>
                        <td valign="top">
                            <asp:Label ID="lblfirstchoiceB" runat="Server" Text='<%#Eval("FIRSTC_B") %>' />
                        </td>
                        <td valign="top">
                            <asp:Label ID="lblfirstchoiceC" runat="Server" Text='<%#Eval("FIRSTC_C") %>' />
                        </td>
 
                    </tr>
                </ItemTemplate>
            </asp:ListView>
       
      </div>
0
 
Jini Jose.Net Team LeadCommented:
where you placed your print button ?
0
 
zachvaldezAuthor Commented:
After the </div>
0
 
zachvaldezAuthor Commented:
It worked nut the printout inckuhes the print button image
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 13
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now