CHA*_*HAS 5 javascript c# database asp.net
我正在使用visual studio 2008和sql server 2008
我想用asp.net中的按钮打印我的"gridview with table" 3.5代码有三个部分,首先是我的默认页面
protected void btnPrint_Click(object sender, EventArgs e)
{
Session["ctrl"] = Panel1;
ClientScript.RegisterStartupScript(this.GetType(), "onclick",
"<script language=javascript>window.open('Print.aspx','PrintMe','height=300px,width=300px,scrollbars=1');</script>");
PrintHelper.PrintWebControl(Panel1);
}
Run Code Online (Sandbox Code Playgroud)
这个代码来自打印页面
protected void Page_Load(object sender, EventArgs e)
{
Control ctrl = (Control)Session["ctrl"];
PrintHelper.PrintWebControl(ctrl);
}
Run Code Online (Sandbox Code Playgroud)
这是我的打印助手类
public PrintHelper()
{
}
public static void PrintWebControl(Control ctrl)
{
PrintWebControl(ctrl, string.Empty);
}
public static void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
Run Code Online (Sandbox Code Playgroud)
请帮帮我
创建一个数据适配器,创建一个带有Select查询的命令对象,将适配器的命令设置为此命令对象,发出adapter.fill(dataset),将gridview的数据源设置为数据集并数据绑定GridView。
对于代码,简单的 Google 搜索就可以了。您甚至没有指定语言。我猜您正在使用 C# 工作,这是您的大学项目。是吗?
| 归档时间: |
|
| 查看次数: |
11786 次 |
| 最近记录: |