Click here to Skip to main content
12,700,773 members (31,676 online)

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
joe_j1-Feb-13 4:21
memberjoe_j1-Feb-13 4:21 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
DaveAuld1-Feb-13 4:32
mentorDaveAuld1-Feb-13 4:32 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Nish Sivakumar1-Feb-13 5:48
sitebuilderNish Sivakumar1-Feb-13 5:48 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
OriginalGriff1-Feb-13 5:59
mvpOriginalGriff1-Feb-13 5:59 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
DaveAuld1-Feb-13 6:45
mentorDaveAuld1-Feb-13 6:45 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Florin Jurcovici7-Feb-13 21:31
memberFlorin Jurcovici7-Feb-13 21:31 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Keith Barrow4-Feb-13 2:42
mentorKeith Barrow4-Feb-13 2:42 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
jibesh4-Feb-13 15:04
memberjibesh4-Feb-13 15:04 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Marco Bertschi6-Feb-13 1:09
memberMarco Bertschi6-Feb-13 1:09 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
satovey7-Feb-13 7:21
membersatovey7-Feb-13 7:21 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
joe_j7-Feb-13 19:50
memberjoe_j7-Feb-13 19:50 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
satovey8-Feb-13 6:16
membersatovey8-Feb-13 6:16 
GeneralRe: supervising stalker eyes onto your screen while you code.. IRRITATING or what??? Pin
Florin Jurcovici7-Feb-13 21:47
memberFlorin Jurcovici7-Feb-13 21:47 
GeneralTwo Approaches to Avoiding Repeating an Item Template Pin
AspDotNetDev31-Jan-13 13:43
protectorAspDotNetDev31-Jan-13 13: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:
<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):
<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:
<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 21:35
memberjoe_j30-Jan-13 21:35 
GeneralRe: Drinking and coding Pin
peterchen30-Jan-13 22:25
memberpeterchen30-Jan-13 22:25 
GeneralRe: Drinking and coding Pin
Jörgen Andersson30-Jan-13 23:09
memberJörgen Andersson30-Jan-13 23:09 
GeneralRe: Drinking and coding Pin
peterchen30-Jan-13 23:11
memberpeterchen30-Jan-13 23:11 
GeneralRe: Drinking and coding Pin
Jörgen Andersson30-Jan-13 23:17
memberJörgen Andersson30-Jan-13 23:17 
GeneralRe: Drinking and coding Pin
Rob Grainger6-Feb-13 23:30
memberRob Grainger6-Feb-13 23:30 
GeneralRe: Drinking and coding Pin
Jörgen Andersson6-Feb-13 23:39
memberJörgen Andersson6-Feb-13 23:39 
GeneralRe: Drinking and coding Pin
RugbyLeague30-Jan-13 22:30
memberRugbyLeague30-Jan-13 22:30 
GeneralRe: Drinking and coding Pin
derek999931-Jan-13 2:47
memberderek999931-Jan-13 2:47 
GeneralRe: Drinking and coding Pin
RugbyLeague31-Jan-13 3:12
memberRugbyLeague31-Jan-13 3:12 
GeneralRe: Drinking and coding Pin
Nagy Vilmos30-Jan-13 22:41
memberNagy Vilmos30-Jan-13 22:41 
GeneralRe: Drinking and coding Pin
joe_j30-Jan-13 23:03
memberjoe_j30-Jan-13 23:03 
GeneralRe: Drinking and coding Pin
Nagy Vilmos30-Jan-13 23:19
memberNagy Vilmos30-Jan-13 23:19 
GeneralRe: Drinking and coding Pin
OriginalGriff31-Jan-13 2:16
mvpOriginalGriff31-Jan-13 2:16 
GeneralRe: Drinking and coding Pin
joe_j1-Feb-13 4:05
memberjoe_j1-Feb-13 4:05 
GeneralRe: Drinking and coding Pin
Scott Burkow1-Feb-13 4:56
memberScott Burkow1-Feb-13 4:56 
GeneralRe: Drinking and coding Pin
Rob Grainger6-Feb-13 23:31
memberRob Grainger6-Feb-13 23:31 
GeneralRe: Drinking and coding Pin
Nagy Vilmos6-Feb-13 23:34
memberNagy Vilmos6-Feb-13 23:34 
GeneralRe: Drinking and coding Pin
Gary Wheeler1-Feb-13 1:33
memberGary Wheeler1-Feb-13 1:33 
GeneralRe: Drinking and coding Pin
joe_j1-Feb-13 2:11
memberjoe_j1-Feb-13 2:11 
GeneralRe: Drinking and coding Pin
S Houghtelin1-Feb-13 3:52
memberS Houghtelin1-Feb-13 3:52 
GeneralIs this bad or am I just picky? Pin
Jeroen De Dauw29-Jan-13 3:44
memberJeroen De Dauw29-Jan-13 3:44 
GeneralRe: Is this bad or am I just picky? Pin
Brisingr Aerowing29-Jan-13 3:56
memberBrisingr Aerowing29-Jan-13 3:56 
GeneralRe: Is this bad or am I just picky? Pin
Jeroen De Dauw29-Jan-13 4:21
memberJeroen De Dauw29-Jan-13 4:21 
JokeRe: Is this bad or am I just picky? Pin
Marcus Kramer29-Jan-13 5:23
mvpMarcus Kramer29-Jan-13 5:23 
GeneralRe: Is this bad or am I just picky? Pin
Bob G Beechey1-Feb-13 18:10
memberBob G Beechey1-Feb-13 18:10 
GeneralRe: Is this bad or am I just picky? Pin
Marcus Kramer1-Feb-13 19:28
mvpMarcus Kramer1-Feb-13 19:28 
GeneralRe: Is this bad or am I just picky? Pin
Bob G Beechey1-Feb-13 19:31
memberBob G Beechey1-Feb-13 19:31 
GeneralRe: Is this bad or am I just picky? Pin
Brady Kelly2-Feb-13 0:56
memberBrady Kelly2-Feb-13 0:56 
GeneralRe: Is this bad or am I just picky? Pin
H.Brydon1-Mar-13 10:39
memberH.Brydon1-Mar-13 10:39 
GeneralRe: Is this bad or am I just picky? Pin
Gary Huck1-Feb-13 4:01
memberGary Huck1-Feb-13 4:01 
GeneralRe: Is this bad or am I just picky? Pin
ihoecken29-Jan-13 23:00
memberihoecken29-Jan-13 23:00 
GeneralRe: Is this bad or am I just picky? Pin
s_mon30-Jan-13 11:03
members_mon30-Jan-13 11:03 
GeneralRe: Is this bad or am I just picky? Pin
Shameel30-Jan-13 23:25
memberShameel30-Jan-13 23:25 
GeneralRe: Is this bad or am I just picky? Pin
jim lahey1-Feb-13 2:19
memberjim lahey1-Feb-13 2:19 
GeneralRe: Is this bad or am I just picky? Pin
S Houghtelin1-Feb-13 2:59
memberS Houghtelin1-Feb-13 2:59 

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.


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 23 Jan 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid