本文介绍了如何打印gridview选定的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将asp.net2.0与c#
一起使用
打印出的纸张尺寸就像商店打印机的小尺寸.
我想打印当前日期,从gridview ItemKey和数量转移编号和两个列.
您可以更正我的代码对我有帮助吗?
Hi ,
I am 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 && ds.Tables != null && ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables["temp"];
GridView1.DataBind();
}
}
推荐答案
<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);
var rows = WinPrint.document.getElementsByTagName('tr');
for(var i=0;i<rows.length;i++)
{
rows[i].removeChild[i]; //item column
}
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
这篇关于如何打印gridview选定的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!