In C# when I programmatically need to get a specific control from a GridView, I insert in my RowDataBound event handler:
HyperLink hl = e.Row.Cells[n].Controls[0] as HyperLink;
How can I get the same result in VB? I tried:
Dim hl = CType(e.Row.Cells(n).Controls(0), HyperLink)
and
Dim hl as HyperLink = CType(e.Row.Cells(n).Controls(0), HyperLink)
but they do not work.
Error 6 Value of type ‘System.Web.UI.Control’ cannot be converted to ‘System.Web.UI.WebControls.HyperLink’.
Anybody know if that is possible?
Look at the TryCast() operator. It is the direct equivalent to C#’s
asoperator.