Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

how to print gridview with paging in vb.net

I am using following code.But its showing empty screen

<script type="text/javascript">
    function CallPrint(strid) {
        var prtContent = document.getElementById(strid);
        var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
        WinPrint.document.write(prtContent.innerHTML);
        WinPrint.document.close();
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();
        prtContent.innerHTML = strOldOne;
    }
</script>
    <title></title>
</head>
<body>
<form runat="server" >
        <div id="prntGrid">
        <asp:GridView ID="grdReg" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" 
        BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" 
        GridLines="Vertical" PageIndex="10" ShowFooter="True" PageSize="20">
        <AlternatingRowStyle BackColor="#CCCCCC" />
        <FooterStyle BackColor="#CCCCCC" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <PagerSettings Mode="NumericFirstLast" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#808080" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#383838" />
        <Columns>
                <asp:BoundField DataField="REGNO" HeaderText="Registration No" />
               
               <asp:TemplateField HeaderText="Patient Name">
                            <ItemTemplate>
                                <asp:Label ID="lblPatName" runat="Server" Text=""></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="400"/>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Age">
                            <ItemTemplate>
                                <asp:Label ID="lblAge" runat="Server" Text="" Width="60px"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                <asp:TemplateField HeaderText="Registration Date">
                            <ItemTemplate>
                                <asp:Label ID="lblDate" runat="Server" Text="" Width="60px"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Adress">
                            <ItemTemplate>
                                <asp:Label ID="lblAdress" runat="Server" Text=""></asp:Label>
                            </ItemTemplate>
                             <ItemStyle Width="1000"/>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Sex">
                            <ItemTemplate>
                                <asp:Label ID="lblSex" runat="Server" Text="" Width="60px"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                <asp:BoundField DataField="REGCONTCODE" HeaderText="Company Code" />
                <asp:BoundField DataField="REGBILLTYPE" HeaderText="Bill Type" />
                <asp:BoundField DataField="REGRESPHONE" HeaderText="Phone No" />
                <asp:BoundField DataField="REGMOBILENO" HeaderText="Mobile No" />
                <asp:BoundField DataField="REGRTNO" HeaderText="RT No" />
         </Columns>
    </asp:GridView>
        </div>
    <div>
  <input id="Button1" type="button" name="btnPrint" value="Print" onClick="javascript:CallPrint('divPrint');" Runat="Server" />
</div>
    </form>
</body>
</html>
Posted

1 solution

 
Share this answer
 
Comments
raj ch 5-Apr-12 6:25am    
thank u soooooo much Uma Shankar ji
uspatel 5-Apr-12 6:26am    
you are most welcome.....
raj ch 6-Apr-12 6:36am    
i have one more doubt

everything is working fine. how can i print it in landscape.
uspatel 6-Apr-12 7:03am    
I think
printing is a client side action of which you have no control.
it is done by client by setting printer setting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900