Although the server control is easy to use, it also sacrifices the performance, and sometimes it appears to be big and useless. Hope you can give me more advice.
Copy codeThe Code is as follows:
/// <Summary>
/// Engineering Performance -- replace DataList with the for loop to display multiple columns. Two rows and four columns of table are obtained, and eight rows of data in the memory table are required.
/// </Summary>
Private void GcyjShow ()
{
StringBuilder sb = new StringBuilder ();
ProductBLL pb = new ProductBLL ();
DataTable dt = pb. GetProductByMoreConditions ("project performance", "Project Performance", "enabled ");
Int count = dt. Rows. Count; // number of Rows
Sb. append ("<table style = 'display: inline; vertical-align: middle; 'cellpadding = '5' align = 'center'>"); // table with four columns in two rows
Sb. Append ("<tr> ");
For (int I = 0; I <count; I ++)
{
DataRow dr = dt. Rows [I];
String strId = dr ["ProdId"]. ToString ();
String strUrl = dr ["Picture"]. ToString ();
String strName = dr ["ProdName"]. ToString ();
If (dr! = Null)
{
Sb. Append ("<td> ");
Sb. Append ("<table border = '0' cellspacing = '0' cellpadding = '0' width = '000000'> ");
Sb. Append ("<tr> ");
Sb. Append ("<td bgcolor = '# ffff'> ");
If (! String. IsNullOrEmpty (strId )&&! String. IsNullOrEmpty (strName )&&! String. IsNullOrEmpty (strUrl ))
{
Sb. Append ("<a title = '/" + strName + "'");
Sb. Append ("href = 'gcyjshow. aspx? StrId = "+ strId +" '> ");
Sb. Append ("Sb. Append (strName + "'");
Sb. Append ("src = '/Photo /");
Sb. Append (strUrl + "'> ");
Sb. Append ("</a> ");
}
Sb. Append ("</td> ");
Sb. Append ("</tr> ");
Sb. Append ("<tr> ");
Sb. Append ("<td> ");
Sb. Append ("<div style = 'padding-left: 15px; background: url (Images/index_r1_c9.jpg) no-repeat '> ");
If (! String. IsNullOrEmpty (strName ))
{
If (strName. Length> 7)
Sb. Append (strName. Substring (0, 7) + "...");
Else
Sb. Append (strName );
}
Sb. Append ("</div> ");
Sb. Append ("</td> ");
Sb. Append ("</tr> ");
Sb. Append ("</table> ");
Sb. Append ("</td> ");
}
// We output the four rows of data in the memory table as four columns and one row.
// If the number of rows in the memory table is count <= 4, that is, if the number is smaller than the number of rows and one column to be displayed, the loop is automatically terminated, and tr is not processed.
// When the same data is equal to four columns (that is, one row) and more than one row-a new line is entered.
If (I = 3 & count> 4)
{
Sb. Append ("</tr> <tr> ");
}
If (I = 7) // when the number of loops reaches 8, a table with four rows and four columns has been completed, and the cycle ends.
{
Break;
}
}
Sb. Append ("</tr> ");
Sb. Append ("</table> ");
LblGcyj. Text = sb. ToString (); // use the Label to output
}