Click here to Skip to main content
15,887,453 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Keith Barrow4-Feb-13 1:42
professionalKeith Barrow4-Feb-13 1:42 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Jibesh4-Feb-13 14:04
professionalJibesh4-Feb-13 14:04 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Marco Bertschi6-Feb-13 0:09
protectorMarco Bertschi6-Feb-13 0:09 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
satovey7-Feb-13 6:21
satovey7-Feb-13 6:21 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
joe_j7-Feb-13 18:50
joe_j7-Feb-13 18:50 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
satovey8-Feb-13 5:16
satovey8-Feb-13 5:16 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Florin Jurcovici7-Feb-13 20:47
Florin Jurcovici7-Feb-13 20:47 
GeneralTwo Approaches to Avoiding Repeating an Item Template Pin
AspDotNetDev31-Jan-13 12:43
protectorAspDotNetDev31-Jan-13 12:43 
An ex-cow-orker needed to create two sections on an ASP.NET webpage with repeated items. Imagine something that gets rendered to HTML like this:
HTML
<h2>First Header</h2>
  <div>Item 1</div>
  <div>Item 2</div>
<h2>Second Header</h2>
  <div>Item 3</div>
  <div>Item 4</div>
  <div>Item 5</div>


To avoid creating two repeaters, they created a single repeater, and then used the pre-render events to add headers to each section. Here's a short version of it (much simplified):
ASP.NET
<script runat="server">
  Private Sub myRepeater_PreRender(sender As Object, e As System.EventArgs) Handles myRepeater.PreRender
    For Each item In myRepeater.Items
      If SomeCondition1() Then
        Dim headerContainer As PlaceHolder = item.FindControl("myHeader")
        AddHeader(headerContainer, "First Header")
      End If
      If SomeCondition2() Then
        Dim headerContainer As PlaceHolder = item.FindControl("myHeader")
        AddHeader(headerContainer, "Second Header")
      End If
    Next
  End Sub
</script>

<asp:Repeater runat="server" ID="myRepeater">
  <ItemTemplate>
    <asp:PlaceHolder ID="myHeader" runat="server" />
    <%-- ...Rest of item template... -->
  </ItemTemplate>
</asp:Repeater>


Not a bad approach, I think, though I'd probably have just created a nested repeater:
XML
<asp:Repeater runat="server" ID="outerRepeater">
  <ItemTemplate>
    <h2><%# HttpUtility.HtmlEncode(DirectCast(Container.DataItem, ItemCollection).HeaderText) %></h2>
    <asp:Repeater runat="server" DataSource="<%# DirectCast(Container.DataItem, ItemCollection).Items %>">
      <ItemTemplate>
        <%-- ...Rest of item template... -->
      </ItemTemplate>
    </asp:Repeater>
  </ItemTemplate>
</asp:Repeater>

Of course, I'd have to split out the collection being bound to into two collections and create some wrapper classes and such, but nothing too difficult. I like this approach more, because you can avoid doing unnecessary processing during the render/binding stages (which just seems like a hack to me).

Another reason I prefer my approach is because you could then sort each collection differently. What I had to do instead was to first sort on SomeCondition1() and SomeCondition2(), then perform a secondary sort (which looks pretty awkward in LINQ).

EDIT: Fixed typo.


modified 31-Jan-13 19:01pm.

GeneralDrinking and coding Pin
joe_j30-Jan-13 20:35
joe_j30-Jan-13 20:35 
GeneralRe: Drinking and coding Pin
peterchen30-Jan-13 21:25
peterchen30-Jan-13 21:25 
GeneralRe: Drinking and coding Pin
Jörgen Andersson30-Jan-13 22:09
professionalJörgen Andersson30-Jan-13 22:09 
GeneralRe: Drinking and coding Pin
peterchen30-Jan-13 22:11
peterchen30-Jan-13 22:11 
GeneralRe: Drinking and coding Pin
Jörgen Andersson30-Jan-13 22:17
professionalJörgen Andersson30-Jan-13 22:17 
GeneralRe: Drinking and coding Pin
Rob Grainger6-Feb-13 22:30
Rob Grainger6-Feb-13 22:30 
GeneralRe: Drinking and coding Pin
Jörgen Andersson6-Feb-13 22:39
professionalJörgen Andersson6-Feb-13 22:39 
GeneralRe: Drinking and coding Pin
RugbyLeague30-Jan-13 21:30
RugbyLeague30-Jan-13 21:30 
GeneralRe: Drinking and coding Pin
derek999931-Jan-13 1:47
derek999931-Jan-13 1:47 
GeneralRe: Drinking and coding Pin
RugbyLeague31-Jan-13 2:12
RugbyLeague31-Jan-13 2:12 
GeneralRe: Drinking and coding Pin
Nagy Vilmos30-Jan-13 21:41
professionalNagy Vilmos30-Jan-13 21:41 
GeneralRe: Drinking and coding Pin
joe_j30-Jan-13 22:03
joe_j30-Jan-13 22:03 
GeneralRe: Drinking and coding Pin
Nagy Vilmos30-Jan-13 22:19
professionalNagy Vilmos30-Jan-13 22:19 
GeneralRe: Drinking and coding Pin
OriginalGriff31-Jan-13 1:16
mveOriginalGriff31-Jan-13 1:16 
GeneralRe: Drinking and coding Pin
joe_j1-Feb-13 3:05
joe_j1-Feb-13 3:05 
GeneralRe: Drinking and coding Pin
Scott Burkow1-Feb-13 3:56
Scott Burkow1-Feb-13 3:56 
GeneralRe: Drinking and coding Pin
Rob Grainger6-Feb-13 22:31
Rob Grainger6-Feb-13 22:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.