如何在C#中获取Table的innerHTML

发布于 2024-11-25 19:11:29 字数 494 浏览 0 评论 0原文

 HtmlTable baseCalendar = new HtmlTable();
 HtmlTableRow calendarRow=new HtmlTableRow();
 HtmlTableCell calendarCell = new HtmlTableCell();

 for(int i=0;i<6;i++){
       calendarCell = new HtmlTableCell();

       calendarCell.Controls.Add(new LiteralControl(i.ToString()));
       calendarCell.Style.Add("color", "red");
       calendarRow.Cells.Add(calendarCell);

 }



 string resutlt=baseCalendar.innerHtml.Tostring();

这行说错误:HtmlTable'不支持InnerHtml属性???

 HtmlTable baseCalendar = new HtmlTable();
 HtmlTableRow calendarRow=new HtmlTableRow();
 HtmlTableCell calendarCell = new HtmlTableCell();

 for(int i=0;i<6;i++){
       calendarCell = new HtmlTableCell();

       calendarCell.Controls.Add(new LiteralControl(i.ToString()));
       calendarCell.Style.Add("color", "red");
       calendarRow.Cells.Add(calendarCell);

 }



 string resutlt=baseCalendar.innerHtml.Tostring();

this line say error:HtmlTable' does not support the InnerHtml property?????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终弃我 2024-12-02 19:11:29

我希望您想要您创建的表的 HTML 代码,这些代码无法通过 innerHTML 实现,这些代码在 div 的情况下是有效的,在这里您应该在这些行上使用 RenderControl 一些东西

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
baseCalendar.RenderControl(htw)

I hope you want the HTML code for the table you created which cannot be achieved by innerHTML those are valid in case of div, here you should rather use RenderControl something on these lines

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
baseCalendar.RenderControl(htw)
司马昭之心 2024-12-02 19:11:29

来自: http ://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable.innerhtml%28VS.80%29.aspx

不要读取或分配该属性的价值。否则,将引发 System.NotSupportedException 异常。该属性继承自 HtmlContainerControl 类,不适用于 HtmlTable 类。

From: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable.innerhtml%28VS.80%29.aspx

Do not read from or assign a value to this property. Otherwise, a System.NotSupportedException exception is thrown. This property is inherited from the HtmlContainerControl class and is not applicable to the HtmlTable class.

梨涡 2024-12-02 19:11:29

这里你必须使用手动编写一个Table而不是使用HtmlTable

 string str = "<table>";
                for (int i = 0; i < 6; i++)
                {
                    str += "<tr><td style='color:red'>" + i.ToString() + "</td></tr>";
                }
                str += "</table>";
                mainDiv.InnerHtml = str;

并且在ASPX页面中

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div runat="server" id="mainDiv">
    </div>
    </form>
</body>
</html>

Here you have to use manually write a Table instead of using HtmlTable

 string str = "<table>";
                for (int i = 0; i < 6; i++)
                {
                    str += "<tr><td style='color:red'>" + i.ToString() + "</td></tr>";
                }
                str += "</table>";
                mainDiv.InnerHtml = str;

And in ASPX page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div runat="server" id="mainDiv">
    </div>
    </form>
</body>
</html>
燕归巢 2024-12-02 19:11:29

HtmlTable 确实具有 InnerHtml 属性: http:/ /msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable.aspx

您缺少一个大写字母:

string resutlt=baseCalendar.innerHtml.Tostring(); // note innerHtml -> InnerHtml

但是,即使它可以编译,您也必须注意:

注意

请勿读取此属性或为其赋值。
否则,将引发 System.NotSupportedException 异常。这
属性是从 HtmlContainerControl 类继承的,而不是
适用于 HtmlTable 类。

A HtmlTable does have the InnerHtml property: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable.aspx

You are missing a caps:

string resutlt=baseCalendar.innerHtml.Tostring(); // note innerHtml -> InnerHtml

However, even though it will compile, you must note that:

Caution

Do not read from or assign a value to this property.
Otherwise, a System.NotSupportedException exception is thrown. This
property is inherited from the HtmlContainerControl class and is not
applicable to the HtmlTable class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文