Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Repeaters in ASP.NET?

I'm a Ruby on Rails / PHP guy, and my company got me to work with ASP.NET. It's not too bad, I'm glad to learn a new language but since I started working with this technology everyone is bothering me about Repeaters.

The thing is that I totally fail of seeing the point: what make using a repeater better than just displaying things in a loop? Am I going to programmers' hell for this?

In rails I would do...

controller

@types= Type.find(:all)

view

 <%@types.each do |t| %>
  <%= t.name %> <%= link_to "view", t%>
 <%end%>

In ASP.NET I'd do:

controller class attributes

protected List<Type> _types = null;

controller class PageLoad

_types = MethodThatGetTypeFromDB();

view

<% foreach (var tin _types){%>
   <%= t.name %>
<%}%>

There are no repeaters, but the code is clean, DRY and respects the MVC AP. I don't create methods everywhere to handle ItemDataBound or whatever. So what's the idea here? Am I the only one that find that repeaters are a pain to set up and are not worth it compared to the advantages they bring?

I think I'm just not getting the idea here.

I'm not trying to start a battle rails vs the world, it's just that this is what I know the best so this is the paradigm I'm trying to find when I'm developing. I think it's more convenient and I'm used to it, but if someone goes "Repeaters are good because A, B and C, doing what you're doing is terrible because D, E and F", then I'll admit it and change my approach.

like image 389
marcgg Avatar asked Jul 08 '09 19:07

marcgg


People also ask

Why Repeater is faster than GridView?

Repeater is faster because it offers only basic data bound control rendering functionalities.

What is a Repeater control?

The Repeater control allows you to split markup tags across the templates. To create a table using templates, include the begin table tag ( <table> ) in the HeaderTemplate, a single table row tag ( <tr> ) in the ItemTemplate, and the end table tag ( </table> ) in the FooterTemplate.

Is GridView or Repeater better?

A GridView control is used when you want to display a set of data in a table format. A Repeater is when you want to display data repeatedly, but not necessarily in a tabular format. If you want a table, use a GridView, otherwise use a Repeater. The speed of loading/updating is negligible between the two.

What is difference between ListView and repeaters?

Between the two, ListView gives you a lot more events and built-in commands for editing, selecting, inserting. Additionally paging and grouping functionality. A Repeater is extremely simple, it repeats a layout with the data. Since you're building the layout by hand, Listview and Repeater require more code.


2 Answers

Repeaters fit nicely into the code-behind approach. I spent many years where I couldn't stand the sight of any code in the markup. All code belonged in the code-behind separated from the markup. This was largely a reaction to the horrid messes I dealt with in classic ASP.

Now with ASP.Net MVC, I find I'm going back to exactly what you describe above. But, I'm finding it hard to overcome the instinct to keep markup and code separate.

Edit: Here's an article from 2003 about the debate regarding code-behind.

like image 104
Geoff Avatar answered Oct 07 '22 15:10

Geoff


Microsoft frequently tries to maximize what you can do without coding. You can do a lot with repeaters without any code-behind. With data source controls you can do a whole lot without any code at all. One can suppose that as a corporate strategy they want to have the easiest-to-use development environment, and "no code at all" is apparently someone's definition of easy to use.

But when you want to move beyond the free automatic behaviors you are knee deep in an event model with lots of twisty passages which all look alike. I am fond of perl's motto, "make the simple things simple and the hard things possible", and Microsoft sometimes seems to prefer "make the simple things trivial and everything else hard".

Some have mentioned that the ASP.Net MVC moves away from this. If true, this is the best news I have heard all day.

like image 40
quillbreaker Avatar answered Oct 07 '22 17:10

quillbreaker