Link to home
Start Free TrialLog in
Avatar of TonyReba
TonyRebaFlag for United States of America

asked on

print checkbox selected

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

Avatar of nmarun
nmarun
Flag of India image

Avatar of TonyReba

ASKER

hmm I am not really get it...

Can you explain me what is wrong in my code?
ASKER CERTIFIED SOLUTION
Avatar of nmarun
nmarun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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
ok testing now