This question already has answers here:
Closed 7 years ago.
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.
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)
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)
Use <asp:literal runat="server" id="lblSomething" />
.
Then in your code behind, write something like this:
lblSomething.Text = "<your table code>";