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" rel="nofollow noreferrer noopener" 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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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)
Method 2
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)
Method 3
Use <asp:literal runat="server" id="lblSomething" />.
Then in your code behind, write something like this:
lblSomething.Text = "<your table code>";
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0