0
Answer

how to print the gridview selected colums using asp.net with c#

charan sekhar

charan sekhar

14y
3.3k
1

 
hi ,
iam using asp.net2.0 with c#
the print out paper size is like shops printer small size
i want to print current date,transfer no and two colums from gridview
 ItemKey and quantity
can you correct my code which helps me

 

  <script language="javascript">
   
    function doPrint()
        {
            var prtContent = document.getElementById('<%= GridView1.ClientID %>');
            prtContent.border = 0; //set no border here
           
            var WinPrint = window.open('','','left=0,top=100,width=80,height=100,toolbar=0,scrollbars=1,status=0,resizable=1');
            WinPrint.document.write(prtContent.outerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }
  
   
   
    </script>
<asp:Button ID="Button2" runat="server" ForeColor="#FF8000" OnClientClick="doPrint()"   OnClick="Button2_Click"
            Style="z-index: 101; left: 896px; position: absolute; top: 80px" Text="Print"
            Width="80px" />
        <asp:GridView ID="GridView1" runat="server" Height="280px" Style="z-index: 103; left: 64px;
            position: absolute; top: 96px" Width="240px">
        </asp:GridView>    
   
protected void Page_Load(object sender, EventArgs e)
   {
       if (Page.IsPostBack == false)
       {
           filldata();
       }
protected void filldata()
    {
                 SqlConnection con = new SqlConnection("Data Source=VER;Initial Catalog=Company;Min Pool Size=5;Max Pool Size=100000;Connect Timeout=100000;User ID=sa;Password=103");
        SqlDataAdapter da = new SqlDataAdapter("select Itemkey,Item,Quantity  from temp where TransferNo=" + Convert.ToInt32(Session["TransferNo"].ToString()) + "", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "temp");
        if (ds != null &amp;&amp; ds.Tables != null &amp;&amp; ds.Tables[0].Rows.Count &gt; 0)
        {
           
            GridView1.DataSource = ds.Tables["temp"];
            GridView1.DataBind();
        }
    }
   }