首页 > 代码库 > ASP.NET- 合并HTML的表格相同项单元格
ASP.NET- 合并HTML的表格相同项单元格
我对控件的依懒是比较少的。有几个控件我比较喜欢用,例如REPEATER显示列表的控件,能提供很大的方便。
使用REPEATER有一个比较方便的功能是通过几句代码就实现了相同项合并单元格合并,这个虽然平时比较少用到,可是有时候客户或者经理比较刁钻的时候,就感觉这个真是好啊!
今天要用AJAX实现一个效果的时候,REPEATER列表控件就没法派上用场,这时我得想办法,根据HTML的一些规律来实现表格相同项的单元格合并。
折腾,终算把效果实现了。备记在这里。
ERP_Reports reprots = new ERP_Reports(); DataTable dtXSSJFX = reprots.GetXSSJFX_DX(txtSDate.Text, txtEDate.Text);//获得销售数据分析报表 if (dtXSSJFX.Rows.Count > 0) { StringBuilder sb = new StringBuilder(); int rowsIndex = 1; for (int i = 0; i < dtXSSJFX.Rows.Count; i++) { if ((i + 1) != dtXSSJFX.Rows.Count) { if (dtXSSJFX.Rows[i]["dlmc"].ToString() == dtXSSJFX.Rows[i + 1]["dlmc"].ToString()) { rowsIndex++; } else { sb.AppendLine("<tr style=\"line-height:24px\" onm ouseout=\"this.style.backgroundColor=backupcolor\" onm ouseover=\"this.backupcolor=this.style.backgroundColor;this.style.backgroundColor=‘#F1F6FF‘\">"); sb.AppendFormat(" <td rowspan=\"{0}\" style=\"text-align: left; width: 100px; \">{1}</td>", rowsIndex, dtXSSJFX.Rows[i]["dlmc"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["jjmc"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["sl_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["je_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["zb_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["sl_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["je_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["zb_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["sl_hj"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["je_hj"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex]["zb_hj"].ToString()); sb.AppendLine("</tr>"); for (int j = 1; j < rowsIndex; j++) { sb.AppendLine("<tr style=\"line-height:24px\" onm ouseout=\"this.style.backgroundColor=backupcolor\" onm ouseover=\"this.backupcolor=this.style.backgroundColor;this.style.backgroundColor=‘#F1F6FF‘\">"); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["jjmc"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["sl_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["je_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["zb_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["sl_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["je_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["zb_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["sl_hj"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["je_hj"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[i + 1 - rowsIndex + j]["zb_hj"].ToString()); sb.AppendLine("</tr>"); } rowsIndex = 1; } } else { sb.AppendLine("<tr style=\"line-height:24px\" onm ouseout=\"this.style.backgroundColor=backupcolor\" onm ouseover=\"this.backupcolor=this.style.backgroundColor;this.style.backgroundColor=‘#F1F6FF‘\">"); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["dlmc"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["jjmc"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["sl_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["je_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["zb_jm"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["sl_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["je_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["zb_zy"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["sl_hj"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["je_hj"].ToString()); sb.AppendFormat(" <td style=\"text-align: left; width: 100px; \">{0}</td>", dtXSSJFX.Rows[dtXSSJFX.Rows.Count - 1]["zb_hj"].ToString()); sb.AppendLine("</tr>"); } } litHTMLS.Text = sb.ToString();
ASP.NET- 合并HTML的表格相同项单元格
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。