- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
gridview的打印功能
实现如下
前端:
[code=csharp]
<script type="text/javascript" language="javascript">
function printPage()
{
var newWindow = window.open('printer','','');
var titleHTML = document.getElementById("printdiv").innerHTML;
newWindow.document.write(titleHTML);
newWindow.document.location.reload();
newWindow.print();
}
</script>
<div id="printdiv">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td >
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
</td>
</tr>
</table>
</div>
<a href="javascript:;" onclick="printPage()">打印</a>[/code]
后端:
[code=csharp]protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = //绑定你的数据源
GridView1.DataBind();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
if (!(control.GetType().Name.Equals("GridView")))
{
base.VerifyRenderingInServerForm(control);
}
}[/code]
好了大家自己研究一下吧
|
|