CopyCode The Code is 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
{
// Step
// 1. There must be a general method to spell strings like private string makestring ()
// 2. There is a way to obtain data in this total method, such as private datatable fetchdata ()
Protected void page_load (Object sender, eventargs E)
{
Response. Write (makestring ());
}
/* This is the method for assembling strings */
private string makestring ()
{< br> datatable dtdata = fetchdata ();
stringbuilder strcontent = new stringbuilder ();
string strformate = " {0} {1} {2} ";
strcontent. append ("
"); foreach (datarow row in dtdata. rows) {< br> strcontent. appendformat (strformate, row [0]. tostring (), row [1]. tostring (), row [2]. tostring (); }< br> strcontent. append ("
");
return strcontent. tostring ();
}
Private datatable fetchdata ()
{
// This is assembly, and you can also obtain it by 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;
}
}