In fact, I wanted to implement this function a long time ago. The data on the Web page is usually exported to excel for printing, A few days ago, I saw that the current online store prints a new webpage. I thought it was a good idea to print it on this webpage, then I wrote a simple answer program based on this. After trying it, I felt pretty good and sent it to share it with you.
I hope you will give your comments.
Parent Page code:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Subpage front-end code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Target.aspx.cs" Inherits="Target" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Subpage background code:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;public partial class Target : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "server=.;database=CheckCardResult;integrated security=true"; try { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT TOP 10 [User_Code],[Meter_Num],[Err_Type],[Err_Time] FROM [CheckCardResult].[dbo].[Result]"; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); this.GridView1.DataSource = ds.Tables[0]; this.GridView1.DataBind(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } }}