using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; /// /// Summary description for ScrollerTable /// public class ScrollerTable { public ScrollerTable() { } /// /// 构造固定表头和固定列的table /// /// 数据表 /// 固定列数(需要固定的列要放在左边) /// 每列宽度 /// public string GetScrollerTable(DataTable obj, int staticColCount, List widthPerCol, int tableWidth, int tableHeight) { //活动表宽 string scrollerTableWidth = GetScrollerTbaleWidth(staticColCount, widthPerCol); //活动div占屏幕宽度 string scrollerDivWidth = GetScrollerDivWidth(staticColCount, widthPerCol, tableWidth); StringBuilder table = new StringBuilder(); table.Append("
"); #region 构造表头 table.Append("
"); #region 构造固定列 if (staticColCount > 0) { table.Append("
"); for (int i = 0; i < staticColCount; i++) { table.Append(""); } table.Append("
" + obj.Columns[i].ColumnName + "
"); } #endregion #region 构造活动列 table.Append("
"); table.Append(" "); for (int i = staticColCount; i < obj.Columns.Count; i++) { table.Append(""); } table.Append("
" + obj.Columns[i].ColumnName + "
"); #endregion table.Append("
"); #endregion #region 构造表主体 table.Append("
"); #region 构造固定列内容 if (staticColCount > 0) { table.Append("
"); foreach (DataRow row in obj.Rows) { table.Append(""); for (int i = 0; i < staticColCount; i++) { table.Append(""); } table.Append(""); } table.Append("
" + row[i] + "
"); } #endregion #region 构造活动列内容 table.Append("
"); table.Append(" "); foreach (DataRow row in obj.Rows) { table.Append(""); for (int i = staticColCount; i < obj.Columns.Count; i++) { table.Append(""); } table.Append(""); } table.Append("
"+ row[i] + "
"); #endregion table.Append("
"); #endregion table.Append("
"); return table.ToString(); } /// /// 获取活动表宽 /// /// /// /// private string GetScrollerTbaleWidth(int staticColCount, List widthPerCol) { int width = 0; for (int i = staticColCount; i < widthPerCol.Count; i++) { width += Convert.ToInt32(widthPerCol[i]); } return width.ToString(); } private string GetScrollerDivWidth(int staticColCount, List widthPerCol, int tableWidth) { int width = 0; for (int i = 0; i < staticColCount; i++) { width += Convert.ToInt32(widthPerCol[i]); } return (tableWidth - width).ToString(); } }