A practical class that displays the content in the datatable in HTML format.

Source: Internet
Author: User
Useful in many cases
For example, if you want to send an email to someone else, the content in this email can only be written in HTML. If it involves data display, it will be very convenient to use it.

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

/** // <Summary>
/// The Z value is defined by yourself, which indicates the number of fields in your able. You can use table. Columns. Count to replace it, so that the total number of fields in the datatable can be automatically obtained.
/// </Summary>
Public class tohtml
{
Public String newhtml (datatable table, int Z)
{
Int hang = table. Rows. count;

String A = "<HTML> ABC ";

A + = "<Table> ";
For (INT I = 0; I {
A + = "<tr> ";
For (Int J = 0; j <z; j ++)
{
A + = "<TD> ";
A + = table. Rows [I] [J];
A + = "</TD> ";
}
A + = "</tr> ";
}
A + = "</table> ";
A + = "Return;
}
}

Hope to help you
Code for impermanence improvement: Public String newhtml (datatable table)
{
Int colcount = table. Columns. count;
Stringbuilder sb = new stringbuilder (1024*5 );
SB. append ("");
For (INT I = 0, rowcount = table. Rows. Count; I <rowcount; I ++)
{
SB. append ("");
Datarow ROW = table. Rows [I];
For (Int J = 0; j <colcount; j ++)
{
SB. append ("");
SB. append (row [J] = NULL? "": Row [J]. tostring ());
SB. append ("");
}
SB. append ("
");
}
SB. append ("");
Return sb. tostring ();
}

This class can also be better written, such as defining the field output (You may only need to output several fields instead of all fields)
The content is relatively simple and should be changed

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.