write this code within your script tag
<script type="text/javascript">
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=400,height=400,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
Then give a id to your content like div as
<div id="divPrint">
<asp:GridView ID="GdviewStockStatment" runat="server" BackColor="Black"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" ShowFooter="true"
PageSize="5" Width="880px"
AutoGenerateColumns="False" ForeColor="Black">
<PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next"
PreviousPageText="Prev" Mode="NextPreviousFirstLast" />
<FooterStyle BackColor="#33A344" ForeColor="#003399"/>
<RowStyle BackColor="White" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="SL.NO." HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblSlno" runat="server" Text='<%#Container.DataItemIndex+1 %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
<Columns>
<%--<asp:TemplateField HeaderText="SL.NO.">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%#Eval ("InvID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Item Category"><ItemTemplate>
<asp:Label ID="lblidItemGroup" runat="server" Text='<%#Eval ("Icategoryname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Name"><ItemTemplate>
<asp:Label ID="lblidItemName" runat="server" Text='<%#Eval ("ItemName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" FooterText="Total Amount:" FooterStyle-HorizontalAlign="Right"><ItemTemplate>
<asp:Label ID="lblidQuantity" runat="server" Text='<%#Eval ("Quantity") %>'></asp:Label>
<asp:Label ID="LabelUMO" runat="server" Text='<%#Eval ("UMO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" ItemStyle-HorizontalAlign="Center">
<%--<ItemTemplate>
<asp:Label ID="lblidAmount" runat="server" Text='<%#Eval ("Amount") %>'></asp:Label>
</ItemTemplate>--%>
<ItemTemplate>
<%# GetUnitPrice3(decimal.Parse(Eval("Amount").ToString())).ToString("N2")%>
</ItemTemplate>
<FooterTemplate>
<%# GetTotal3().ToString("N2") %>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#009900" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#009933" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#33A344" ForeColor="Black" />
</asp:GridView>
</div>
Then take button to print this
<input type="button" value="print " id="btnPrint1" runat="Server"
onclick="javascript:CallPrint('divPrint2')"
style="color: #FFFFFF; background-color: #339933; margin-left:-120px; width:60px" visible="True" />
<script type="text/javascript">
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=400,height=400,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
Then give a id to your content like div as
<div id="divPrint">
<asp:GridView ID="GdviewStockStatment" runat="server" BackColor="Black"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" ShowFooter="true"
PageSize="5" Width="880px"
AutoGenerateColumns="False" ForeColor="Black">
<PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next"
PreviousPageText="Prev" Mode="NextPreviousFirstLast" />
<FooterStyle BackColor="#33A344" ForeColor="#003399"/>
<RowStyle BackColor="White" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="SL.NO." HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblSlno" runat="server" Text='<%#Container.DataItemIndex+1 %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
<Columns>
<%--<asp:TemplateField HeaderText="SL.NO.">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%#Eval ("InvID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Item Category"><ItemTemplate>
<asp:Label ID="lblidItemGroup" runat="server" Text='<%#Eval ("Icategoryname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Name"><ItemTemplate>
<asp:Label ID="lblidItemName" runat="server" Text='<%#Eval ("ItemName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" FooterText="Total Amount:" FooterStyle-HorizontalAlign="Right"><ItemTemplate>
<asp:Label ID="lblidQuantity" runat="server" Text='<%#Eval ("Quantity") %>'></asp:Label>
<asp:Label ID="LabelUMO" runat="server" Text='<%#Eval ("UMO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" ItemStyle-HorizontalAlign="Center">
<%--<ItemTemplate>
<asp:Label ID="lblidAmount" runat="server" Text='<%#Eval ("Amount") %>'></asp:Label>
</ItemTemplate>--%>
<ItemTemplate>
<%# GetUnitPrice3(decimal.Parse(Eval("Amount").ToString())).ToString("N2")%>
</ItemTemplate>
<FooterTemplate>
<%# GetTotal3().ToString("N2") %>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#009900" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#009933" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#33A344" ForeColor="Black" />
</asp:GridView>
</div>
Then take button to print this
<input type="button" value="print " id="btnPrint1" runat="Server"
onclick="javascript:CallPrint('divPrint2')"
style="color: #FFFFFF; background-color: #339933; margin-left:-120px; width:60px" visible="True" />
i think its the simple way to explain how to print
ReplyDelete