print listview

I have 9 cold listview that I wanted to print.This is asp.net app not windows.how is that done?
zachvaldezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jini JoseSenior .Net DeveloperCommented:
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 JoseSenior .Net DeveloperCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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 JoseSenior .Net DeveloperCommented:
<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 JoseSenior .Net DeveloperCommented:
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 JoseSenior .Net DeveloperCommented:
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 JoseSenior .Net DeveloperCommented:
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 JoseSenior .Net DeveloperCommented:
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 JoseSenior .Net DeveloperCommented:
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 JoseSenior .Net DeveloperCommented:
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 JoseSenior .Net DeveloperCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.