Search:
Namespaces
Discussions
.NET v1.1
Feedback
control question
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngcontrolsvb' list
.
Cameron Elliot
-- Copied from [aspngfreeforall] to [aspngcontrolsvb] by Tim Musschoot <
Click here to reveal e-mail address
> --
Hi,
I have created a few of my own user and custom controls and have =
discovered through msdn how to created databound templated controls. =
What I would like to know is how to create a control/class similar to =
ListItem
where free text can go in between the open and close tag.
ie <blah:CustomListItem value=3D"1">one</blah:CustomListItem>
How is it the the text 'one' gets assigned to the ListItem's Text =
property? Would be great if I had the source code so I could see how =
this is done.
Any suggestions welcome.
Cameron
Reply to this message...
Emil Christopher Melar
I will with pleasure and proudness show you how:
NOTE: This is in VB, convert to C# if needed!
-
Private _itemTemplate As
ITemplate
= Nothing 'Declares the template to
be implemented.
...
<TemplateContainer(GetType(ExMenuItem))> Public Property ItemTemplate()
As
ITemplate
Get
Return _itemTemplate
End Get
Set(ByVal Value As ITemplate)
_itemTemplate = Value
End Set
End Property
...
Public Class ExMenuItem : Inherits Control : Implements
INamingContainer
Private _ItemIndex As Integer
Private _DataItem As Object
Public Sub New(ByVal ItemIndex As Integer, ByVal DataItem As Object)
MyBase.New()
_ItemIndex = ItemIndex
_DataItem = DataItem
End Sub
Public ReadOnly Property DataItem() As Object
Get
Return _DataItem
End Get
End Property
Public ReadOnly Property ItemIndex() As Integer
Get
Return _ItemIndex
End Get
End Property
...
INSIDE ONDATABINDING:
Dim DataEnum As
IEnumerator
= DataSource.GetEnumerator()
Dim I As Integer = 0
Do While (DataEnum.MoveNext())
' create item
Dim Item As ExMenuItem = New ExMenuItem(I,
DataEnum.Current)
' initialize item from template
ItemTemplate.InstantiateIn(Item)
' add item to the child controls collection
WHATEVER.Controls.Add(Item) ' where whatever is your
placeholder
I = I + 1
Loop
' prevent child controls from being created again
ChildControlsCreated = True
' store the number of items created in viewstate for
postback scenarios
ViewState("NumItems") = I
End If
---
That's the VERY basics... Itemtemplate.. Now outside the loop, you can
implement headers and footers :)
...
Public Class ExMenuMainFooter : Inherits Control : Implements
INamingContainer
Private _DataItem As Object
Public ReadOnly Property DataItem() As Object
Get
Return _DataItem
End Get
End Property
End Class
---
ETC
Get it?
-
Emil Chr. Melar
-----Original Message-----
From: Cameron Elliot [mailto:
Click here to reveal e-mail address
]
Sent: 20. mai 2002 22:39
To: aspngcontrolsvb
Subject: [aspngcontrolsvb] control question
-- Copied from [aspngfreeforall] to [aspngcontrolsvb] by Tim Musschoot
<
Click here to reveal e-mail address
> --
Hi,
I have created a few of my own user and custom controls and have =
discovered through msdn how to created databound templated controls. =
What I would like to know is how to create a control/class similar to =
ListItem
where free text can go in between the open and close tag.
ie <blah:CustomListItem value=3D"1">one</blah:CustomListItem>
How is it the the text 'one' gets assigned to the ListItem's Text =
property? Would be great if I had the source code so I could see how =
this is done.
Any suggestions welcome.
Cameron
| [aspngcontrolsvb] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngcontrolsvb.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
Reply to this message...
System.Collections.IEnumerator
System.Web.UI.INamingContainer
System.Web.UI.ITemplate
System.Web.UI.MobileControls.TemplateContainer
System.Web.UI.WebControls.ListItem
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com