Example #1
0
        /// <summary>
        /// 添加行
        /// </summary>
        /// <param name="rowAction"></param>
        /// <returns></returns>
        public DataTableFactory AddDataTableRow(Action <DataTableRow> rowAction = null)
        {
            var row = new DataTableRow();

            if (rowAction != null)
            {
                rowAction(row);
            }
            if (_table == null)
            {
                throw new Exception("请先创建Table实例");
            }
            _table.Rows.Add(row);
            return(this);
        }
Example #2
0
        /// <summary>
        /// 创建一行
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private string RenderRow(DataTableRow row)
        {
            if (!row.Columns.Any())
            {
                return("");
            }
            var trBuilder = new TagBuilder("tr");
            var isThead   = row.IsThead;

            foreach (var column in row.Columns)
            {
                var tdBuilder = isThead ? new TagBuilder("th") : new TagBuilder("td");
                tdBuilder.InnerHtml = column.Value;
                //给单元格添加样式名
                if (!string.IsNullOrEmpty(column.ClassName))
                {
                    tdBuilder.AddCssClass(column.ClassName);
                }
                trBuilder.InnerHtml += tdBuilder;
            }

            return(trBuilder.ToString());
        }