Skip Navigation Links
More In Javascript
 Generating Sequence Number-Serial Number-Row Number in DataGrid GridView...
 Fixed gridview/datagrid header while scrolling Asp.Net...
 Print particular area of page in Asp.Net...
 Creating Backup, Compress and FTP Sql Server Database...

Hiding Gridview column while printing

There are times that we require a column of the gridview not to get printed while taking their print from the browser.
Their are various different ways to do so but i will describe the simplest and the efficient way to achieve the same functionality.

In the header section of aspx page write the following code :

 <style type="text/css">
         @media Print
         {
             .noprint
             {
                 DISPLAY: none
             }
         }
 </style>

YOu can also use the above code with Asp.net 2.0 master files.

Now just use the "noprint" class with the columns that you dont want to get printed

Example:

 

 

  <asp:GridView ID="gvNoPrintTesting" runat="server">

                <Columns>

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

                    <asp:TemplateField HeaderText="Email Id" ControlStyle-CssClass="noprint" HeaderStyle-CssClass="noprint">

                       <ItemTemplate>

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

                        </ItemTemplate>

                    </asp:TemplateField>

                </Columns>

            </asp:GridView>

 

In the above example the second tablerow won't get printed.