How to insert tag in the table in asp.net in c

2020-04-21 08:31发布

Possible Duplicate:
How do I dynamically create new Hyperlinks in ASP.NET?

I am adding tables dynamically in my code. i want to add this using coding in my code behind file. My code is given below:

<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>

Can anyone tell me how to add this through code?

code added from comments

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

Thanks in advance.

3条回答
欢心
2楼-- · 2020-04-21 08:50

What you want to do is add a HyperLink control to your Cell

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)
查看更多
兄弟一词,经得起流年.
3楼-- · 2020-04-21 09:05

Use <asp:literal runat="server" id="lblSomething" />.

Then in your code behind, write something like this:

lblSomething.Text = "<your table code>";
查看更多
成全新的幸福
4楼-- · 2020-04-21 09:08

Create a HyperLink object in code, assign all the relevant data to it, then add it to the relevant cell.

So something like

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)
查看更多
登录 后发表回答