Search code examples
c#hyperlinkdynamic-data

Creating Hyperlink in Dynamically Created Table error 'Table' cannot have children of type 'HyperLink'.


I am trying to create a hyperlink in a table cell, this is what I have so far.

I error out with this message, "'Table' cannot have children of type 'HyperLink'."

How can I fix this?

    TableRow Label11 = new TableRow();
    TableCell Label11TC = new TableCell();
    HyperLink P30HL = new HyperLink();
    P30HL.NavigateUrl = "http://endor/RequestIT/Remee/test/Details.aspx";
    P30HL.Text = (work / dda).ToString("p");
    Label11.Cells.Add(Label11TC);
    Table1.Controls.Add(P30HL);

Solution

  • You need to place the hyperlink into a table cell instead of the table...

    TableRow Label11 = new TableRow();
    TableCell Label11TC = new TableCell();
    HyperLink P30HL = new HyperLink();
    P30HL.NavigateUrl = "http://endor/RequestIT/Remee/test/Details.aspx";
    P30HL.Text = (work / dda).ToString("p");
    Label11.Cells.Add(Label11TC);
    Label11TC.Controls.Add(P30HL);