.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification