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;
}