asp.net打印- -

None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Text;
None.gif
None.gif
namespace  bookstore
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif 
/**//// <summary>
InBlock.gif 
/// myPrint 的摘要说明。
ExpandedSubBlockEnd.gif 
/// </summary>

InBlock.gif public class myPrint
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
public myPrint()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 拼出要打印的表
InBlock.gif  
/// </summary>
InBlock.gif  
/// <param name="ds">DATASET</param>
InBlock.gif  
/// <param name="dg">DATAGRID</param>
ExpandedSubBlockEnd.gif  
/// <returns></returns>

InBlock.gif  public string DGPrint(DataSet ds,DataGrid dg)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
//*****************************************************************************************//
InBlock.gif

InBlock.gif   DataTable myDataTable
=new DataTable();
InBlock.gif   myDataTable
=ds.Tables[0];
InBlock.gif
InBlock.gif   
int myRow=myDataTable.Rows.Count; 
InBlock.gif   
int myCol=dg.Columns.Count;
InBlock.gif
InBlock.gif   StringBuilder sb
=new StringBuilder();  
InBlock.gif     
InBlock.gif 
InBlock.gif   
string colHeaders="<html><body>"+
InBlock.gif    
"<object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'VIEWASTEXT></object>"
InBlock.gif    
+"<table><tr>";  
InBlock.gif
InBlock.gif   
for(int i=0;i<myCol;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{     
InBlock.gif    colHeaders 
+="<td>"+ dg.Columns[i].HeaderText.ToString()+"</td>";
ExpandedSubBlockEnd.gif   }

InBlock.gif   colHeaders 
+= "</tr>";
InBlock.gif
InBlock.gif   sb.Append(colHeaders);
InBlock.gif
InBlock.gif   
for(int i=0;i<myRow;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{       
InBlock.gif    sb.Append(
"<tr>");
InBlock.gif    
for(int j=0;j<myCol;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     sb.Append(
"<td>");
InBlock.gif     sb.Append(myDataTable.Rows[i][j].ToString().Trim());
InBlock.gif     sb.Append(
"</td>");
ExpandedSubBlockEnd.gif    }

InBlock.gif    sb.Append(
"</tr>");   
ExpandedSubBlockEnd.gif   }

InBlock.gif
InBlock.gif   sb.Append(
"</table></body></html>"); 
InBlock.gif   colHeaders
=sb.ToString();               
InBlock.gif
InBlock.gif   colHeaders
+="<scrip languge='javascript'>WebBrowser.ExecWB(7,1); window.opener=null;window.close();</script>" ;
InBlock.gif
InBlock.gif   
return(colHeaders);
InBlock.gif
InBlock.gif   
//*****************************************************************************************//
InBlock.gif
   
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
///  拼出要打印的表
InBlock.gif  
/// </summary>
InBlock.gif  
/// <param name="dg">datagrid</param>
ExpandedSubBlockEnd.gif  
/// <returns></returns>

InBlock.gif  public string DGPrint(DataGrid dg)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
int myRow=dg.Items.Count;   
InBlock.gif   
int myCol=dg.Columns.Count;
InBlock.gif
InBlock.gif   StringBuilder sb
=new StringBuilder();           
InBlock.gif 
InBlock.gif   
string colHeaders="<html> body>"+
InBlock.gif    
"<object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'VIEWASTEXT></object>"
InBlock.gif    
+"<table><tr>";  
InBlock.gif
InBlock.gif   
for(int i=0;i<myCol;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    colHeaders 
+="<td>"+ dg.Columns[i].HeaderText.ToString()+"</td>";
ExpandedSubBlockEnd.gif   }

InBlock.gif   colHeaders 
+= "</tr>";
InBlock.gif
InBlock.gif   sb.Append(colHeaders);
InBlock.gif
InBlock.gif   
for(int i=0;i<myRow;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{       
InBlock.gif    sb.Append(
"<tr>");
InBlock.gif    
for(int j=0;j<myCol;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     sb.Append(
"<td>");
InBlock.gif     sb.Append(dg.Items[i].Cells[j].Text.Trim());
InBlock.gif     sb.Append(
"</td>");
ExpandedSubBlockEnd.gif    }

InBlock.gif    sb.Append(
"</tr>");   
ExpandedSubBlockEnd.gif   }

InBlock.gif
InBlock.gif   sb.Append(
"</table></body></html>"); 
InBlock.gif   colHeaders
=sb.ToString();               
InBlock.gif
InBlock.gif   colHeaders
+="<script languge='javascript'>WebBrowser.ExecWB(7,1); window.opener=null;window.close();</script>" ;
InBlock.gif
InBlock.gif   
return(colHeaders);
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
None.gif
None.gif

转载于:https://www.cnblogs.com/coolylh/archive/2005/11/14/275878.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值