Asp.net uses the for loop to display Datalist Columns

Source: Internet
Author: User

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
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.