根据是奇数行还是偶数行来实现
StringBuilder builder = new StringBuilder(); builder.Append(string.Format("document.write(\"<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>\");\n")); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { switch (_type) { case 1: if ((i % 2) == 0) { builder.Append(string.Format("document.write(\"<td><img src='showimages/news2.jpg' /></td><td><a href='{0}' target='_blank' title='{1}'>{2}</a></td><td></td>\");\n", pageUrl, title, Settings.SubStr(title, _length, 3))); } else if ((i % 2) == 1) { builder.Append(string.Format("document.write(\"<td><img src='showimages/news2.jpg' /></td><td><a href='{0}' target='_blank' title='{1}'>{2}</a></td></tr><tr>\");\n", pageUrl, title, Settings.SubStr(title, _length, 3))); } break; } } builder.Append(string.Format("document.write(\"</tr></table>\");\n"));