I am building a custom repeater control that wraps it's content in parentheses based on conditions. It is work somewhat. It works perfectly if my template does not contain controls but if I were to add controls to the template (LinkButtons/TextBox) then the controls are never wrapped in the parentheses. Examples of the templates and the code is below. Could anyone tell me why this happens and how I might do this so that my controles will be rendered enclosed in parentheses.
This works perfectly
<itemtemplate>
<%# Eval("Name") %>
</itemtemplate>
With this I get nothing
<itemtemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Name") %>' />
</itemtemplate>
Public Class MyRepeater
Inherits Repeater
Protected Overrides Sub RenderChildren(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim YItems, NItems, CItems As Collection
Dim parenOpen As New LiteralControl
parenOpen.Text = " ("
Dim parenClose As New LiteralControl
parenClose.Text = ")"
YItems = New Collection
NItems = New Collection
For Each control As Web.UI.Control In Controls
Dim strWriter As New IO.StringWriter
Dim htmlWriter As New HtmlTextWriter(strWriter)
control.RenderControl(htmlWriter)
Dim strBuilder As Text.StringBuilder
strBuilder = strWriter.GetStringBuilder
Dim strItem As String = strBuilder.ToString()
strItem = strItem.Trim()
Select Case strItem.Substring(strItem.Length - 1)
Case "Y"
YItems.Add(strItem.Substring(0, strItem.Length - 2))
Case "N"
NItems.Add(strItem.Substring(0, strItem.Length - 2))
Case Else
NItems.Add(strItem)
End Select
Next
RenderControls(NItems, writer)
If YItems.Count > 0 Then
parenOpen.RenderControl(writer)
RenderControls(YItems, writer)
parenClose.RenderControl(writer)
End If
End Sub
Private Sub RenderControls(ByVal items As Collection, ByVal writer As System.Web.UI.HtmlTextWriter)
End Sub
End Class