本文介绍了获取的HTMLTABLE C#的innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该函数返回一个HTML表格:

this function is returning an HTML table:

private HtmlTable ConvertToHtml(DataTable dataTable)
        {
            var htmlTable = new HtmlTable();
            if (dataTable == null) return htmlTable; //null reference, empty table

            HtmlTableRow htmlRow = new HtmlTableRow();
            htmlTable.Rows.Add(htmlRow);

            foreach (DataColumn column in dataTable.Columns)
                htmlRow.Cells.Add(new HtmlTableCell() { InnerText = column.ColumnName });

            foreach (DataRow row in dataTable.Rows)
            {
                htmlRow = new HtmlTableRow();
                htmlTable.Rows.Add(htmlRow);

                foreach (DataColumn column in dataTable.Columns)
                    htmlRow.Cells.Add(new HtmlTableCell() { InnerText = row[column].ToString() });
            }

            return htmlTable;
        }

我想知道我可以得到的innerHTML HTMLTABLE

目前,我这样做是:

        var bodyhtml = ConvertToHtml(r.tblSalesVolume);
        MessageBox.Show(bodyhtml.InnerHtml);

但它说,它不具有这样的属性。

but it says that it doesnt have such a property.

我如何获得的HTML $ C $下表?

how do i get the HTML code for the table?

推荐答案

您可以使用HtmlTable.RenderControl()方法。

You can use HtmlTable.RenderControl() method.

例如:

StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);

HtmlTable.RenderControl(hw);
String HTMLContent = sb.ToString();

这篇关于获取的HTMLTABLE C#的innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 13:52