如何在文件中 asp.net 的表中插入<href>标签?



可能的重复项:
如何在 ASP.NET 中动态创建新的超链接?

我正在我的代码中动态添加表。 我想在我的代码隐藏文件中使用编码来添加它。我的代码如下:

<table>
<tr>
     <td class="what-to-expect">
        <a href="#TB_inline?height=200&width=300&inlineId=myOnPageContent" title="add a caption to title attribute" class="thickbox">?</a>
        </td>
</tr>
</table>

谁能告诉我如何通过代码添加它?

从注释添加的代码

HtmlTableRow trContent = new HtmlTableRow(); 
HtmlTableCell cell1 = new HtmlTableCell(); 
cell1.InnerText = SomeTextHere; 
trContent.Cells.Add(cell1)

提前谢谢。

您要

做的是将HyperLink控件添加到单元格

HtmlTableRow trContent = new HtmlTableRow(); 
HtmlTableCell cell1 = new HtmlTableCell(); 
HyperLink hl = new HyperLink() 
{ 
    Text = "?", 
    NavigateUrl = "#TB_inline?height=200&width=300&inlineId=myOnPageContent",
    CssClass="thickbox", 
    ToolTip = "add a caption to title attribute" 
};
cell1.Controls.Add(hl); 
trContent.Cells.Add(cell1)

在代码中创建一个 HyperLink 对象,为其分配所有相关数据,然后将其添加到相关单元格。

所以像

Dim link As New HyperLink()
link.NavigateURL = "#TB_inline?height=200&width=300&inlineId=myOnPageContent"
link.ToolTip = "add a caption to title attribute"
link.CssClass = "thickbox"
link.Text = "?"
cell1.Controls.Add(link)

使用 <asp:literal runat="server" id="lblSomething" />

然后在你的代码隐藏中,写如下内容:

lblSomething.Text = "<your table code>";

最新更新