如何插入<a href=""> tag in the table in asp.net in code behind file?</a>

时间:2012-04-23 08:57:38

标签: c# asp.net hyperlink html-table

  

可能重复:
  How do I dynamically create new Hyperlinks in 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)

提前致谢。

3 个答案:

答案 0 :(得分:4)

您要做的是向您的单元格添加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)

答案 1 :(得分:2)

在代码中创建一个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)

答案 2 :(得分:0)

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

然后在你的代码中,写下这样的东西:

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