lidt hjælp til ny metode i linkdictionary class
hejsa...jeg fandt denne snippet på nettet igår.
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'START
''''''''''''''''''''''''''''''''''''''''''''''''''''''
<%@ Page Language="VB" debug="true" trace="true"%>
<%@ Import namespace="System.Collections"%>
<script language="VB" runat="server">
Public Class LinkDictionary
Inherits DictionaryBase
#Region "Public Methods"
Public Sub Add(ByVal link_val As Link)
MyBase.Dictionary.Add(link_val.LinkID, link_val)
End Sub
Public Sub Add(ByVal LinkId As Integer, ByVal LinkText As String, ByVal LinkHref As String, _
ByVal LinkTarget As String, ByVal LinkOnClick As String)
MyBase.Dictionary.Add(LinkId, New Link(LinkId, LinkText, LinkHref, LinkTarget, LinkOnClick))
End Sub
Public Sub Remove(ByVal LinkId As Integer)
MyBase.Dictionary.Remove(LinkId)
End Sub
Public Sub Remove(ByVal cust As Link)
MyBase.Dictionary.Remove(cust.LinkID)
End Sub
Public Function Contains(ByVal cust As Link) As Boolean
Return MyBase.Dictionary.Contains(cust.LinkID)
End Function
Public Function Contains(ByVal LinkId As Integer) As Boolean
Return MyBase.Dictionary.Contains(LinkId)
End Function
#End Region
#Region "Properties"
Default Public Property Item(ByVal LinkId As Integer) As Link
Get
Return MyBase.Dictionary.Item(LinkId)
End Get
Set(ByVal Value As Link)
MyBase.Dictionary.Item(LinkId) = Value
End Set
End Property
#End Region
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
Public Class Link ': Inherits System.Web.UI.Page
Private mLinkId As Integer
Private mLinkText As String
Private mLinkOnClick As String
Private mLinkHref As String
Private mLinkTarget As String
#Region "Constructors"
Public Sub New(ByVal Linkid As Integer, _
ByVal LinkText As String, _
ByVal LinkHref As String, _
ByVal LinkTarget As String)
mLinkId = Linkid
mLinkText = LinkText
mLinkHref = LinkHref
mLinkTarget = LinkTarget
mLinkOnClick = ""
End Sub
Public Sub New(ByVal Linkid As Integer, _
ByVal LinkText As String, _
ByVal LinkHref As String)
mLinkId = Linkid
mLinkText = LinkText
mLinkHref = LinkHref
mLinkTarget = ""
mLinkOnClick = ""
End Sub
Public Sub New(ByVal Linkid As Integer, _
ByVal LinkText As String, _
ByVal LinkHref As String, _
ByVal LinkTarget As String, _
ByVal LinkOnClick As String)
mLinkId = Linkid
mLinkText = LinkText
mLinkHref = LinkHref
mLinkTarget = LinkTarget
mLinkOnClick = LinkOnClick
End Sub
#End Region
#Region "Properties"
Public Property LinkID() As Integer
Get
Return mLinkId
End Get
Set(ByVal Value As Integer)
mLinkId = Value
End Set
End Property
Public Property LinkText() As String
Get
Return mLinkText
End Get
Set(ByVal Value As String)
mLinkText = Value
End Set
End Property
Public Property LinkHref() As String
Get
Return mLinkHref
End Get
Set(ByVal Value As String)
mLinkHref = Value
End Set
End Property
Public Property LinkTarget() As String
Get
Return mLinkTarget
End Get
Set(ByVal Value As String)
mLinkTarget = Value
End Set
End Property
Public Property LinkOnClick() As String
Get
Return mLinkOnClick
End Get
Set(ByVal Value As String)
mLinkOnClick = Value
End Set
End Property
#End Region
End Class
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sub page_load
Dim links As New LinkDictionary()
links.Add(1, "Overview", "//localhost/sms", "_self","")
links.Add(2, "Whats includet", "//localhost/sms", "_self","")
links.Add(3, "Jack", "//localhost/sms", "_self","")
links.Add(4, "Bones", "//localhost/", "_self","")
links.Add(5, "Linko", "//localhost/", "_self","")
links.Add(6, "Linko", "//localhost/", "_self","")
links.Add(7, "Linko", "//localhost/", "_self","")
links.Add(8, "Linko", "//localhost/", "_self","")
links.Add(9, "Linko", "//localhost/", "_self","")
Dim i as integer
for i = 1 to 9
z.Controls.Add(new literalcontrol("<a href='" & links(i).Linkhref & "' id='" & links(i).LinkId & "' target='" & links(i).LinkTarget & "' onclick='" & links(i).LinkOnClick & "'>" & links(i).LinkText & "</a><br>"))
next
end sub
</script>
<html>
<head>
<title>construct.aspx</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<asp:placeholder ID="z" runat="server" />
</body>
</html>
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'SLUT
''''''''''''''''''''''''''''''''''''''''''''''''''''''
jeg syntes det er en smart og nem måde at udskrive links på, men der er en lille ting jeg tænker på om kan lade sig gøre, men jeg kan ikke selv finde ud af det da jeg stadig er for newbie ?
i page_load() definerer jeg mine links og udskriver til en placeholder gennem et loop.
Kan man ikke lave en metode der gør dette stykke arbejde for mig ?
Altså sådan så jeg kan ligge class'erne i en selvstændig fil, og det eneste jeg skal skrive i min page_load() er:
Dim links As New LinkDictionary()
links.Add(1, "Overview", "//localhost/sms", "_self","")
links.Add(2, "Whats includet", "//localhost/sms", "_self","")
links.udskriv()