在很多場合下有用
比如要發送一封Email給別人,這個Email裡面的內容自然只能用Html來寫,如果涉及到數據顯示的話,用這個會很方便

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>

/// 其中z的值是自己定義的,表示你datatable中的字段數量

/// </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 < hang; i++)


{

a += " <tr> ";

for (int j = 0; j < z; j++)


{

a += " <td> ";

a += table.Rows[i][j];

a += " </td> ";

}

a += "</tr>";

}

a += " </table> ";

a += " </Html> ";

return a ;

}

}
希望對大家有幫助
這個類還可以寫的更完善,比如具體定義那些字段輸出(也許你可能只需要輸出其中的幾個字段而不是所有字段)
內容比較簡單,應該都會改