Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I have a gridview and i want when i am click on the print button then all the data show in the center of page and a header show of the upper of gridview.
Posted
Comments
Orcun Iyigun 23-Sep-13 5:06am    
And what is blocking you? Binding the gv? Showing it in the middle? What have you tried?
indiancodinglove 23-Sep-13 5:16am    
yes i am binding the data to gridview and show it to middle.

http://www.codeproject.com/Articles/196579/How-to-Print-Invoice-using-C

i am trying this code but in my code gridview and header are the same point not show it in the middle

private void ReadInvoiceHead() {

//Titles and Image of invoice:

InvTitle = "RAVI PRAKASH ";

InvSubTitle1 = "23,SABJI MANDI";

InvSubTitle2 = "DHAMPURAJK,BIJNOREDKJE";

InvSubTitle3 = "Phone -133444246346";

InvSubTitle4 = "Created By Indian";

InvImage = Application.StartupPath + @"\Images\" + "InvPic.jpg";

} private void SetInvoiceHead(Graphics g) {

ReadInvoiceHead(); CurrentY = topMargin;

CurrentX = leftMargin; int ImageHeight = 0;

// Draw Invoice image:

if (System.IO.File.Exists(InvImage)) {

Bitmap oInvImage = new Bitmap(InvImage);

// Set Image Left to center Image:

int xImage = CurrentX + (InvoiceWidth - oInvImage.Width) / 2;

ImageHeight = oInvImage.Height; // Get Image Height

g.DrawImage(oInvImage, xImage, CurrentY); }

InvTitleHeight = (int)(InvTitleFont.GetHeight(g));

InvSubTitleHeight = (int)(InvSubTitleFont.GetHeight(g));

// Get Titles Length:

int lenInvTitle = (int)g.MeasureString(InvTitle, InvTitleFont).Width;

int lenInvSubTitle1 = (int)g.MeasureString(InvSubTitle1, InvSubTitleFont).Width;

int lenInvSubTitle2 = (int)g.MeasureString(InvSubTitle2, InvSubTitleFont).Width;

int lenInvSubTitle3 = (int)g.MeasureString(InvSubTitle3, InvSubTitleFont).Width;

int lenInvSubTitle4 = (int)g.MeasureString(InvSubTitle4, InvSubTitleFont).Width;

// Set Titles Left:

int xInvTitle = CurrentX + (InvoiceWidth - lenInvTitle) / 2;

int xInvSubTitle1 = CurrentX + (InvoiceWidth - lenInvSubTitle1) / 2;

int xInvSubTitle2 = CurrentX + (InvoiceWidth - lenInvSubTitle2) / 2;

int xInvSubTitle3 = CurrentX + (InvoiceWidth - lenInvSubTitle3) / 2;

// Draw Invoice Head: if (InvTitle != "") {

CurrentY = CurrentY + ImageHeight;

g.DrawString(InvTitle, InvTitleFont, BlueBrush, xInvTitle, CurrentY);

} if (InvSubTitle1 != "") {

CurrentY = CurrentY + InvTitleHeight;

g.DrawString(InvSubTitle1, InvSubTitleFont, BlueBrush, xInvSubTitle1, CurrentY);

} if (InvSubTitle2 != "") {

CurrentY = CurrentY + InvSubTitleHeight;

g.DrawString(InvSubTitle2, InvSubTitleFont, BlueBrush, xInvSubTitle2, CurrentY);

} if (InvSubTitle3 != "") {

CurrentY = CurrentY + InvSubTitleHeight;

g.DrawString(InvSubTitle3, InvSubTitleFont, BlueBrush, xInvSubTitle3, CurrentY);

} // Draw line:

CurrentY = CurrentY + InvSubTitleHeight + 8;

g.DrawLine(new Pen(Brushes.Black, 2), CurrentX, CurrentY, rightMargin, CurrentY);

}
Orcun Iyigun 23-Sep-13 5:40am    
Are you sure you dont have any CSS applied to it?

1 solution

i think than it is easier to do it with javascript.
 <script type="text/javascript" language="javascript">

        function CallPrint(strid) {
            var prtContent = document.getElementById(strid);
            var WinPrint = window.open('', '', 'letf=0,top=0,width=860,height=800,toolbar=0,scrollbars=0,status=0');
            WinPrint.document.write(prtContent.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }
</script>



And then
XML
<input type="image" runat ="server" id ="Image1" src ="/images/images.jpg" onclick="javascript: CallPrint('divPivot1')" title="Print" />

                               <br />
                               <div id= "divPivot1">
                               <asp:GridView ID="OrderGridView" runat="server" AllowPaging="True"
                                   BorderStyle="None" CellPadding="3" DataKeyNames="Article"
                                   Font-Size="Small" HorizontalAlign="Left"
                                   OnPageIndexChanging="OrderGridView_PageIndexChanging" PageSize="20"
                                   TabIndex="15" Width="866px" BackColor="White" BorderColor="#CCCCCC"
                                   BorderWidth="1px">
                                   <FooterStyle BackColor="White" ForeColor="#336699" />
                                   <HeaderStyle BackColor="#336699" Font-Bold="True" ForeColor="White" />
                                   <PagerSettings FirstPageText="First" LastPageText="Last" />
                                   <PagerStyle BackColor="White" ForeColor="#336699" HorizontalAlign="Left" />
                                   <RowStyle ForeColor="#336699" Font-Size="Small" />
                                   <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                                   <SortedAscendingCellStyle BackColor="#F1F1F1" />
                                   <SortedAscendingHeaderStyle BackColor="#007DBB" />
                                   <SortedDescendingCellStyle BackColor="#CAC9C9" />
                                   <SortedDescendingHeaderStyle BackColor="#00547E" />
                                   <Columns>
                                       <asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center" >
                                       <ItemTemplate>
                                           <asp:CheckBox ID="CheckBox1" runat="server" />
                                       </ItemTemplate>
                                       </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Update Cartons Quant." ItemStyle-HorizontalAlign="Center" ItemStyle-Width="40">
                                       <ItemTemplate>
                                           <asp:TextBox ID="TextBox" runat="server" Width="90" />
                                       </ItemTemplate>
                                       </asp:TemplateField>
                                   </Columns>
                               </asp:GridView>
<br /></div>


everything inside DIV will be printed
 
Share this answer
 
v3
Comments
indiancodinglove 25-Sep-13 2:59am    
i am creating a window based application with c# and sql database.

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