Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a contacts page, with many categories. Not all categories will have contacts in them, but all categories will be shown on the page (populated or empty).

I would like to create a repeater for each of the categories and fill it with an ItemTemplate. The repeater, item template and inner html i wish to create in the code behind file.

My issue is i don't know how to create a generic ItemTemplate with my own html, as everytime i set repeater.ItemTemplate i have to pick from a predefined like GridTemplate or ListItemTemplate etc.

existing code i have so far:

VB
Public Sub BuildRepeater()
          'types are the contact categories'
          For Each itemType In types
              Dim sb As New StringBuilder()
              sb.Append("<div class=""contact-fieldset"">")
              sb.Append("<h2><%# Eval(""FullName"") %></h2>")
              sb.Append("<h4><%# Eval(""TypeName"") %></h4>")
              sb.Append("<p><%# Eval(""Address"") %></p>")
              sb.Append("<label style=""display:<%# IIF(Eval(""WorkPhone"") <> DBNull.Value.ToString(),""block"",""none"")%>""class=""contact-label"">Work Phone: </label>")
              sb.Append("<p style=""display:<%# IIF(Eval(""WorkPhone"") <> DBNull.Value.ToString(),""block"",""none"")%>""><%# Eval(""WorkPhone"") %></p>")
              sb.Append("<label style=""display:<%# IIF(Eval(""Mobile"") <> DBNull.Value.ToString(),""block"",""none"")%>"" class=""contact-label"">Mobile: </label>")
              sb.Append("<p style=""display:<%# IIF(Eval(""Mobile"") <> DBNull.Value.ToString(),""block"",""none"")%>""><%# Eval(""Mobile"") %></p>")
              sb.Append("<label class=""contact-label"">Email: </label>")
              sb.Append("<a href=""mailto:<%# Eval(""Email"")%>""><%# Eval(""Email"")%></a>")
              sb.Append("</div>")
              sb.ToString()

              Dim repeater As New Repeater()
              repeater.DataSource = (From c In contacts _
                                     Where c.TypeName = itemType.Name _
                                     Select c).ToList()

              repeater.DataBind()
              repeater.ItemTemplate = [add code here to get sb.tostring]
              contactList.Controls.Add(repeater)
          Next
      End Sub
Posted
Updated 27-Aug-15 1:35am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900