Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Data;
Using System.Text;
public partial class Default2:System.Web.UI.Page
{
Steps
1. There's a general way to spell a string like a private string makestring ()
2. In this general approach, there's a way to get the data, like a private DataTable fetchdata ()
protected void Page_Load (object sender, EventArgs e)
{
Response.Write (Makestring ());
}
* * This is the method of assembling the string.
private String makestring ()
{
DataTable dtdata = Fetchdata ();
StringBuilder strcontent = new StringBuilder ();
String strformate = "<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr > ";
Strcontent.append ("<table>");
foreach (DataRow row in dtdata.rows)
{
Strcontent.appendformat (Strformate, row[0). ToString (), row[1]. ToString (), row[2]. ToString ());
}
Strcontent.append ("</table>");
return strcontent.tostring ();
}
Private DataTable Fetchdata ()
{
It's assembled, and you can get it yourself.
DataTable dtdata = new DataTable ();
DTDATA.COLUMNS.ADD ("C1");
DTDATA.COLUMNS.ADD ("C2");
DTDATA.COLUMNS.ADD ("C3");
DTDATA.ROWS.ADD (new string[] {"1-1", "1-2", "1-3"});
DTDATA.ROWS.ADD (new string[] {"2-1", "2-2", "2-3"});
DTDATA.ROWS.ADD (new string[] {"3-1", "3-2", "3-3"});
DTDATA.ROWS.ADD (new string[] {"4-1", "4-2", "4-3"});
DTDATA.ROWS.ADD (new string[] {"5-1", "5-2", "5-3"});
return dtdata;
}
}