server controls, while convenient to use, also sacrifice performance, and sometimes seem accuse. Hope that advanced friends more advice.
Copy Code code as follows:
<summary>
Engineering performance--with a for loop instead of the DataList multiple-column display, get 2 rows of four columns of the table, requires a memory table of 8 rows of data
</summary>
private void Gcyjshow ()
{
StringBuilder sb = new StringBuilder ();
PRODUCTBLL PB = new Productbll ();
DataTable dt = PB. Getproductbymoreconditions ("Project Performance", "Project Performance", "Enable");
int count = dt. rows.count;//Number of rows
Sb. Append ("<table style=" display:inline; Vertical-align:middle ' cellpadding= ' 5 ' align= ' center ' > ')//two rows of four-column tables
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= ' 100% ' >");
Sb. Append ("<tr>");
Sb. Append ("<td bgcolor= ' #ffffff ' >");
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 4 rows of data in the memory table as a row of 4 columns
If the number of rows in the memory table is count<=4, which is less than the row column we want to display, it automatically terminates the loop and does not need to process TR
When the data equals four columns (that is, one row) and is larger than a row-wrap
if (i = = 3 && count > 4)
{
Sb. Append ("</tr><tr>");
}
if (i = = 7)////When the loop reaches 8 times, a table of two rows four columns is completed, and the loop is terminated at this time
{
Break
}
}
Sb. Append ("</tr>");
Sb. Append ("</table>");
Lblgcyj.text = sb. ToString ()////label label to output
}