Asp.net 2.0 ie print directly-the skill example only prints the printed content

Source: Internet
Author: User

 

As the project needs to be printed, and not the actual content on the Web page needs to be printed, only part of the content is printed.
The following code is provided to share with you. Skill examples only print <! -- Startprint --> printed <! -- Endprint -->.

Page code: print. aspx

<! 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">
<Head runat = "server">
<Title> Print ie directly </title>

<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function Preview ()
{
Bdhtml###doc ument. Body. innerhtml;
Sprnstr = "<! -- Startprint --> ";
Eprnstr = "<! -- Endprint --> ";
Prnhtml = bdhtml. substr (bdhtml. indexof (sprnstr) + 17 );
Prnhtml = prnhtml. substring (0, prnhtml. indexof (eprnstr ));
Too many Doc ument. Body. innerhtml = prnhtml;
Window. Print ();
}
</SCRIPT>

</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Center>
This part is not printed
<! -- Startprint -->
<Div>
<Asp: gridview id = "gridview1" runat = "server">
</ASP: gridview>
</Div>
<! -- Endprint -->
This section is not printed below
<Div>
<Input type = "button" name = "print" value = "preview and print" onclick = "Preview ()"/>
</Div>
</Center>
</Div>
</Form>
</Body>
</Html>

. CS Page code:

Protected void page_load (Object sender, eventargs E)
{
This. gridview1.datasource = createtable ();
This. gridview1.databind ();
}

/// <Summary>
/// Create a able
/// </Summary>
/// <Returns> </returns>
Private datatable createtable ()
{
// Define the table
Datatable TB = new datatable ("newtb ");
Datacolumn column;
Datarow row;

// Create an ID column
Column = new datacolumn ();
Column. datatype = system. type. GetType ("system. int32 ");
Column. columnname = "ID ";
Column. readonly = true;
Column. Unique = true;
// Add the ID column to the table
TB. Columns. Add (column );

// Create a parentitem Column
Column = new datacolumn ();
Column. datatype = system. type. GetType ("system. String ");
Column. columnname = "parentitem ";
Column. autoincrement = false;
Column. Caption = "parentitem ";
Column. readonly = false;
Column. Unique = false;
// Add the parentitem column to the table
TB. Columns. Add (column );

// Fill in data
For (INT I = 0; I <= 2; I ++)
{
Row = Tb. newrow ();
Row ["ID"] = I;
Row ["parentitem"] = "parentitem" + I;
TB. Rows. Add (ROW );
}
// Return table
Return TB;
}

 

 

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.