VB.NET & CType() - CType() : Returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.
ShotDev Focus:
- VB.NET & CType()
Example
CType.aspx
- <%@ Page Language="VB" %>
- <script runat="server">
- Sub Page_Load(sender As Object, e As EventArgs)
- Dim i As Integer
- For i = 1 To 4
- Dim lblLabel = CType(Me.FindControl("lblText"&i),Label)
- IF Not IsNothing(lblLabel) Then
- lblLabel.Text = "www.ShotDev.Com " & i
- End IF
- Next
- End Sub
- </script>
- <html>
- <head>
- <title>ShotDev.Com Tutorial</title>
- </head>
- <body>
- <form runat="server">
- <asp:Label id="lblText1" runat="server"></asp:Label><br />
- <asp:Label id="lblText2" runat="server"></asp:Label><br />
- <asp:Label id="lblText3" runat="server"></asp:Label><br />
- <asp:Label id="lblText4" runat="server"></asp:Label><br />
- </form>
- </body>
- </html>
Screenshot