Print results in Asp.net

Source: Internet
Author: User

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();         }    }}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.