Solved

print checkbox selected

Posted on 2010-08-29
6
468 Views
Last Modified: 2012-05-10
How can I print in my above Javascript only those records which checkbox status is selected..

right now it just shows print preview page with all elements

Thanks!!


aspx:

                <asp:CheckBox ID="CheckBoxPrintProvider" runat="server" Text="Print this Provider" />

            <asp:HyperLink ID="HyperLink1"  runat="server" Text="Click to See a Map" NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Address").ToString) + "," + Server.UrlEncode(Eval("City").ToString) + "," + Server.UrlEncode(Eval("State").ToString) %>'   />                                             

            </td></tr>

            </table>

            <br />

        </ItemTemplate>





 <asp:Button ID="btnPrint" runat="server" Text="Print Selected Providers" />





Javascript:

//Generating Pop-up Print Preview page

function getPrint(print_area) {



  boxes = document.getElementsByTagName('input');

   

   for(var i=0; i < boxes.length; i++)

    

         { 

   

     if (boxes[i].getAttribute('type') == 'checkbox' && boxes[i].checked)

          {



             //Creating new page

             var pp = window.open();

             //Adding HTML opening tag with <HEAD> … </HEAD> portion 

             pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')

             pp.document.writeln('<LINK href=Styles.css type="text/css" rel="stylesheet">')

             pp.document.writeln('<LINK href=PrintStyle.css ' +

                                        'type="text/css" rel="stylesheet" media="print">')

             pp.document.writeln('<base target="_self"></HEAD>')



             //Adding Body Tag

             pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');

             pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');

             //Adding form Tag

             pp.document.writeln('<form method="post">');



             //Creating two buttons Print and Close within a HTML table

             pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');

             pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');

             pp.document.writeln('onclick="javascript:location.reload(true);window.print();">');

             pp.document.writeln('<INPUT ID="CLOSE" type="button" ' +

                                        'value="Close" onclick="window.close();">');

             pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');



             //Writing print area of the calling page

             pp.document.writeln(document.getElementById(print_area).innerHTML);

            // pp.document.writeln(GetCheckedValues(print_area));



             //Ending Tag of </form>, </body> and </HTML>

             pp.document.writeln('</form></body></HTML>');



         }     

    }

}

Open in new window

0
Comment
Question by:TonyReba
  • 3
  • 3
6 Comments
 
LVL 27

Expert Comment

by:nmarun
ID: 33555792
0
 
LVL 9

Author Comment

by:TonyReba
ID: 33555850
hmm I am not really get it...

Can you explain me what is wrong in my code?
0
 
LVL 27

Accepted Solution

by:
nmarun earned 500 total points
ID: 33556036
I won't be able to explain your code, because I'm don't see the entire html of the grid control you have there. But I'll give you a snippet of something that worked on my box.

Arun

// aspx of the GridView

<asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="False" Width="400px">

    <Columns>

        <asp:TemplateField>

            <ItemTemplate>

                <asp:CheckBox ID="PrintBox" runat="server" />

            </ItemTemplate>

        </asp:TemplateField>

        <asp:BoundField DataField="FirstName" HeaderText="First Name" />

        <asp:BoundField DataField="LastName" HeaderText="Last Name" />

    </Columns>

</asp:GridView>

<br/>

<asp:Button ID="Click" runat="server" OnClientClick="return openWindow();" Text="Click" />



// javascript function

<script language="javascript" type="text/javascript">

    function openWindow() {

        var pp = window.open();

        //Adding HTML opening tag with <HEAD> … </HEAD> portion 

        pp.document.writeln('<HTML><HEAD><title>Print Preview</title></HEAD>')



        //Adding Body Tag

        pp.document.writeln('<body>');

        var gridViewCtlId = '<%=gvTest.ClientID%>';

        var tableElement = document.getElementById(gridViewCtlId);

        for (var i = 1; i < tableElement.rows.length; i++) {

            var rowElem = tableElement.rows[i];

            var printBoxName = rowElem.cells[0].childNodes[0].name;

            var printBox = document.getElementsByName(printBoxName);

            if (printBox[0].checked) {

                for (var x = 1; x < rowElem.cells.length; x++) {

                    pp.document.writeln(rowElem.cells[x].childNodes[0].data);

                    pp.document.writeln(' ');

                }

                pp.document.writeln('<br/>');

            }

        }

        pp.document.writeln('</body></html>');

    }



</script>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Author Comment

by:TonyReba
ID: 33558114
actually this is a different control....
is an asp.net 3.5 listview,, how can I do the same on that control?

<asp:ListView ID="ListView1" runat="server"   DataSourceID="AccessDataSource2" 

        Visible="False"  >



         <EmptyDataTemplate>

         <span></span>

        </EmptyDataTemplate>

    <GroupTemplate>

            <tr ID="itemPlaceholderContainer" runat="server">

                <td ID="itemPlaceholder" runat="server">

                </td>

            </tr>

        </GroupTemplate>

 

  <ItemTemplate>

        <br />

        <table id="TableItemTemplate"  runat= "server" class="itemTemplateClass">

     

 <tr>

    <td >

      <b>

            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Last_Name") %>' />

            ,

             <asp:Label ID="Label2" runat="server" 

             Text='<%# Eval("First_Name") %>' />

             

               <asp:Label ID="Label3" runat="server" 

             Text='<%# Eval("Prof_Designation") %>' />

             </b>

             </td>

             </tr>

             <tr>

             <td>

            <asp:Label ID="Label4" runat="server" Text='<%# Eval("Specialty") %>' />

            <asp:Label ID="Label5" runat="server" 

            Text='<%# Eval("[Specialty2]") %>' />

            <br/>

            <asp:Label ID="Label6" runat="server" Text='<%# Eval("Address") %>' />

            <br/>

            <asp:Label ID="Label7" runat="server" Text='<%# Eval("Address2") %>' />

           <br/>

            <asp:Label ID="Label8" runat="server" Text='<%# Eval("City") %>' />

            ,

            <asp:Label ID="Label9" runat="server" Text='<%# Eval("State") %>' />

            ,

            <asp:Label ID="Label10" runat="server" Text='<%# Eval("Zip") %>' />

           <br/>

            <asp:Label ID="Label11" runat="server" Text='<%# Eval("Phone") %>' />

            <br/>

            <asp:Label ID="Label12" runat="server" Text='<%# Eval("Fax") %>' />  

            <br />

            <asp:CheckBox ID="CheckBoxPrintProvider" runat="server" Text="Print this Provider" />

            <asp:HyperLink ID="HyperLink1"  runat="server" Text="Click to See a Map" NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Address").ToString) + "," + Server.UrlEncode(Eval("City").ToString) + "," + Server.UrlEncode(Eval("State").ToString) %>'   />                                             

            </td></tr>

            </table>

            <br />

        </ItemTemplate>



      <AlternatingItemTemplate>

      <table id="TableAlternativeItemTemplate"  runat= "server" class="alternateitemTemplateClass"   >

  <tr>

    <td >

      <b>

            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Last_Name") %>' />

            ,

             <asp:Label ID="Label2" runat="server" 

             Text='<%# Eval("First_Name") %>' />

             

               <asp:Label ID="Label3" runat="server" 

             Text='<%# Eval("Prof_Designation") %>' />

             </b>

             </td>

             </tr>

             <tr>

             <td>

            <asp:Label ID="Label4" runat="server" Text='<%# Eval("Specialty") %>' />

            <asp:Label ID="Label5" runat="server" 

            Text='<%# Eval("[Specialty2]") %>' />

            <br/>

            <asp:Label ID="Label6" runat="server" Text='<%# Eval("Address") %>' />

            <br/>

            <asp:Label ID="Label7" runat="server" Text='<%# Eval("Address2") %>' />

           <br/>

            <asp:Label ID="Label8" runat="server" Text='<%# Eval("City") %>' />

            ,

            <asp:Label ID="Label9" runat="server" Text='<%# Eval("State") %>' />

            ,

            <asp:Label ID="Label10" runat="server" Text='<%# Eval("Zip") %>' />

           <br/>

            <asp:Label ID="Label11" runat="server" Text='<%# Eval("Phone") %>' />

            <br/>

            <asp:Label ID="Label12" runat="server" Text='<%# Eval("Fax") %>' />

            

            <br />

            <asp:CheckBox ID="CheckBoxPrintProvider2" runat="server" Text="Print this Provider" />

            <asp:HyperLink ID="HyperLink2"  runat="server" Text="Click to See a Map" NavigateUrl='<%# "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" + Server.UrlEncode(Eval("Address").ToString) + "," + Server.UrlEncode(Eval("City").ToString) + "," + Server.UrlEncode(Eval("State").ToString) %>'   />

            </td>

            </tr>

            </table>

       </AlternatingItemTemplate>

   

   <LayoutTemplate>



   

             <table id="Table1"cellpadding="0" cellspacing="0" style="border-right: #000000 thin solid; border-top: #000000 thin solid;

                                    border-left: #000000 thin solid; border-bottom: #000000 thin solid; background-color: #FFFFFF; border-width: 1px;"

                                    width="100%" align="center" class="NoDisplay">

        <tr>

            <td class="style2">

                    <b>Matching Providers </b>

                   </td>

            <td>

                &nbsp;</td>

        </tr>

        <tr>

            <td class="style2">

                             Sort By: 

                                 <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="Last_Name">Name</asp:LinkButton>&nbsp;Sort 

                By:   

                                 <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Sort" CommandArgument="City">City</asp:LinkButton>

                <br />

            </td>

            <td>

                        <%--<asp:Button ID="PrintButton" runat="server" Text="Print Selected Providers"  />--%>

                        <asp:Button ID="btnPrint" runat="server" Text="Print Selected Providers" />

                   &nbsp;

                   <asp:CheckBox ID="chkSelectAll" runat="server" Text=" Select All For Printing" AutoPostBack="true" OnClick="selectAll(this)" />

                                    </td>

        </tr>

    </table>

    

                        <table ID="groupPlaceholderContainer" runat="server" border="1" 

                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">

                            <tr ID="groupPlaceholder" runat="server">

                            </tr>

                        </table>

                                                

                    </td>

                </tr>

                <tr id="Tr2" runat="server">

                    <td id="Td2" runat="server" 

                        style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">

                        <br />

                        <asp:DataPager ID="DataPager1" runat="server" PageSize="12">

                            <Fields>

                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 

                                    ShowLastPageButton="True" />

                            </Fields>

                        </asp:DataPager>

                    </td>

                </tr>

            </table>

             

        </LayoutTemplate>

        

    </asp:ListView>

Open in new window

0
 
LVL 27

Expert Comment

by:nmarun
ID: 33558294
That should be fine. All you need to do is to modify the indexes in the javascript function. I'm afraid I won't be able to give you the actual JS function as I don't have the datasource needed to populate the listbview.

Arun
0
 
LVL 9

Author Comment

by:TonyReba
ID: 33558315
ok testing now
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular- typeahead works but need to change 2 things 5 19
IIS Authorization for Web Service 2 24
Change javascript css 1 21
how can i count words? 2 21
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now