Use custom labels, XML, and XSL to display data in Asp.net (C #).

Source: Internet
Author: User

Label Definition CopyCode The Code is as follows: public class Encoding
{
Public String encode (string csource)
{
Return System. Web. httputility. htmlencode (csource );
}
}
Public class emlist: Label
{
Public override bool enableviewstate
{
Get {return false ;}
}
Public String folder file {Get; set ;}
Public object serialobject {Get; set ;}
Protected override void render (htmltextwriter writer)
{
If (serialobject = NULL)
{
Throw new exception ("the object is not initialized ");
}
System. xml. serialization. xmlserializer oserial = new system. xml. serialization. xmlserializer (serialobject. GetType ());
System. Text. stringbuilder OSB = new system. Text. stringbuilder ();
System. Io. stringwriter owr = new system. Io. stringwriter (OSB );
String xml = "";
Oserial. serialize (owr, serialobject );
Xml = OSB. tostring ();
String cxslfilename = This. mappathsecure (Secure File );
If (! System. Io. file. exists (cxslfilename ))
{
Throw new exception ("add your own exception Program ");
}
System. xml. XSL. encode targumentlist into ARGs = new system. xml. XSL. encode targumentlist ();
Encoding oen = new encoding ();
Xslargs. addextensionobject ("urn: encoding", Oen );
System. xml. xmldocument odoc = new system. xml. xmldocument ();
Try
{
Odoc. loadxml (XML );
}
Catch
{
Throw new exception ("add your own exception handling program ");
}
System. xml. XSL. Compile compiledtransform otran = new system. xml. XSL. Compile compiledtransform ();
String cxsl = "";
Try
{
Cxsl = system. Io. file. readalltext (cxslfilename );
}
Catch
{
Throw new exception ("add your own exception handling program ");
}
System. Io. stringreader OSR = new system. Io. stringreader (cxsl );
System. xml. xmlreader ORE = system. xml. xmlreader. Create (OSR );
Try
{
Otran. Load (ore );
}
Catch
{
Throw new exception ("add your own exception handling program ");
}
Try
{
Otran. Transform (odoc, xslargs, writer );
}
Catch
{
Throw new exception ("add your own exception handling program ");
}
}
}
Public class pagebar: system. Web. UI. htmlcontrols. htmlcontrol
{
Public int pagenum {Get; set ;}
Public int pagesize {Get; set ;}
Public int pagecount {Get; set ;}
Public String baseurl {Get; set ;}
Protected override void render (htmltextwriter writer)
{
Writer. Write (string. Format ("<a href = {0 }? Pagenum = 1> page 1 </a> | <a href = {0 }? Pagenum = {1}> previous page </a> | <a href = {0 }? Pagenum ={ 2}> next page </a> | <a href = {0 }? Pagenum = {3}> last page </a> ({4} current page {5}) ", baseurl, pagenum-1> 0? Pagenum-1: 1, pagenum + 1> pagecount? Pagecount: pagenum + 1, pagecount, pagecount, pagenum ));
}
}

Page Definition Copy codeThe Code is as follows: <% @ page Language = "C #" autoeventwireup = "true" codebehind = "default. aspx. cs" inherits = "webapplication1. _ default" %>
<% @ Register tagprefix = "CS" namespace = "webapplication1.control" assembly = "webapplication1" %>
<! 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> </title>
</Head>
<Body>
<CS: emlist serialobject = "<% # List %>" using file = "XSL/test. XSLT" runat = "server"/> <br/>
<CS: pagebar pagenum = "<% # pagenum %>" baseurl = "<% # request. PATH %>" pagecount = "5" runat = "server"/>
</Body>
</Html>

The list and pagenum are page attributes.

XSLT: copy Code the code is as follows:





]>



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.