从GRIDVIEW打印记录 [英] Printing the Records from GRIDVIEW
本文介绍了从GRIDVIEW打印记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
在我的项目中,我有一个gridview和Print按钮.我需要从Gridview中打印数据.我已经在Gridview中很好地显示了数据.但是有些错误.
请给我建议.如何从gridview完美打印数据.
这是我的代码.
Hello Frnds,
In my project i have a gridview and Print button.I need to print the Data from Gridview. Already i have Displayed the Data in Gridview its Fine. But some Errors.
Please can you advice me. How to print the data perfectly from gridview.
This is my code.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.IO;
using System.Text;
protected void BtnCurrentPage_Click(object sender, EventArgs e)
{
GridView1.PagerSettings.Visible = false;
GridView1.DataBind();
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
string gridHtml = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, "");
StringBuilder sb = new StringBuilder();
sb.Append("");
ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
GridView1.PagerSettings.Visible = true;
GridView1.DataBind();
}
这是执行后单击打印"按钮后出现的错误.
This is the ERROR what am getting after clicking on Printbutton after Execution.
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
请任何人对此有想法.请给我找到解决方法.
谢谢,
Please anybody have idea about this. please find me a solution.
Thanks,
推荐答案
使用此类进行打印
^ ]
Use this class to print
http://www.dotnetcurry.com/ShowArticle.aspx?ID=92[^]
尝试
http://www.aspsnippets.com/Articles/Print-functional- in-ASP.Net-GridView-control.aspx [ ^ ]
使用分页打印GridView [ http://www.deanblakely.com/PrintGrid.aspx [
Try
http://www.aspsnippets.com/Articles/Print-functionality-in-ASP.Net-GridView-control.aspx[^]
Printing a GridView with Paging[^]
http://www.deanblakely.com/PrintGrid.aspx[^]
这篇关于从GRIDVIEW打印记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文