本文介绍了如何在不切断的情况下打印gridview所有列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户详细信息表,有56列。

我在GridView中显示一些行。

当我从GridView打印数据时,它只打印12列;剩余的所有列数据都被切断了。



我想要两个解决方案

要么

1)打印所有列无论数据是否可读,无论如何条件都在单页(横向/纵向模式)上



2)必须在第二页上打印任何剪切数据。 />




这是我的HTML代码:



< html xmlns = http://www.w3.org/1999/xhtml\">

< head runat =server>

< title>< / title> ;

< style type =text / cssmedia =print>

div {

float:none;

显示:阻止;

}

< / style>

< / head>

< body>

< form id =form1runat =server>

< div>

< asp:GridView ID =GridView1runat =serverAutoGenerateColumns =FalseDataKeyNames =AuditPlanIdDataSourceID =SqlDataSource1>



//我的列列表(59列)



< / asp:GridView>

< asp:SqlDataSource ID =SqlDataSource1runat =serverConnectionString =<%$ ConnectionStrings:EX%> SelectCommand =SELECT TOP 100 * FROM [MstrAuditPlan]>< / asp:SqlDataSource>

< asp:Button ID =Button1runat =serverText =ButtonOnClick =Button1_Click/>

< / div>

< / form>

< / body>

< / html>





和打印PrintBtn_Click

I have a customer details table which having 56 columns.
I display some rows in GridView.
When I print the data from GridView it only printing starting 12 columns; all remaining columns data cutting off.

I want two solution
Either
1) Print all columns in anyhow condition on single page (Landscape/portrait mode) no matter if data is readable or not
OR
2) Whatever cut data must be print on second page.


Here is my HTML code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css" media="print">
div {
float :none;
display: block;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="AuditPlanId" DataSourceID="SqlDataSource1">

//my columns list (59 columns)

</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EX %>" SelectCommand="SELECT TOP 100 * FROM [MstrAuditPlan]"></asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>


and for Print on PrintBtn_Click

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("<script type = 'text/javascript'>");
            sb.Append("window.onload = new function(){");
            sb.Append("var printWin = window.open('', '', 'left=0");
            sb.Append(",top=0,width=1000,height=600,status=0');");
            sb.Append("printWin.document.write(\"");
            sb.Append(gridHTML);
            sb.Append("\");");
            sb.Append("printWin.document.close();");
            sb.Append("printWin.focus();");
            sb.Append("printWin.print();");
            sb.Append("printWin.close();};");
            sb.Append("</script>");
            ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
            GridView1.PagerSettings.Visible = true;
            GridView1.DataBind();





我尝试过:



< style type =text / cssmedia =print>

div {

float:none;

display:block;

}

< / style>



What I have tried:

<style type="text/css" media="print">
div {
float :none;
display: block;
}
</style>

推荐答案

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("<script type = 'text/javascript'>");
            sb.Append("window.onload = new function(){");
            sb.Append("var printWin = window.open('', '', 'left=0");
            sb.Append(",top=0,width=1000,height=600,status=0');");
            sb.Append("printWin.document.write(\"");
            sb.Append(gridHTML);
            sb.Append("\");");
            sb.Append("printWin.document.close();");
            sb.Append("printWin.focus();");
            sb.Append("printWin.print();");
            sb.Append("printWin.close();};");
            sb.Append("</script>");
            ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
            GridView1.PagerSettings.Visible = true;
            GridView1.DataBind();





我尝试过:



< style type =text / cssmedia =print>

div {

float:none;

display:block;

}

< / style>



What I have tried:

<style type="text/css" media="print">
div {
float :none;
display: block;
}
</style>


这篇关于如何在不切断的情况下打印gridview所有列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 02:01