Ever questioned the implementation of the
Repeater control? Yes we've all had requirements where this control comes in handy. The thing that detracted me and many developers I've spoken with is the use of
DataBinder.Eval in the front end code. There are online examples that attempt to explain everything that needs to happen to move the binding logic to the compiled code, but once more, I learned that I had to figure out the details on my own. Next time you need the repeater functionality, stop struggling with HTML in the code to generate your output, and wincing at
DataBinder.Eval in the front end code. When you understand these method's you'll be satisfied with the repeater at last.
Front end code
The front end code with these methods is very light and simple. The only catch is to make sure you import the
System.Data namespace. Even with this method, we need to use
DataRowView in the front end. Take a special note: when you nest these
Repeaters, the designer will whine like a baby in a two dollar crib.
To pacify the baby, you need to comment out the parent
Repeater, if you want to return to the designer to work with other controls. You better know markup language, if you can't code this by hand, you're already in over your head. In that case, I would recommend w3schools.com :-).
Please note that the tag "
sItemTemplate" is really supposed to be "ItemTemplate" but something about the CodeProject rejects that in the code block.
Also note that the front end does not care about the DataSource. The container knows what source to choose for your column-name keys upon binding. You may proceed to the server code now:
<%@ Control Language="c#" AutoEventWireup="false"
<%@ Import namespace="System.Data" %>
I have given you one generic method that handles your data and binding, only to illustrate the necessary steps. I'm quite sure, you are a master of your data at this point so I've excluded impertinent details about data retrieval and manipulation. Pay special attention to the comments.
protected void massageData()
DataSet resultSet = new DataSet("resultSet");
DataTable AreaDT = new DataTable("AreaDT");
DataTable PropertyDT = new DataTable("PropertyDT");
AreaResults.DataSource = resultSet.Tables["AreaDT"];
AreaResults.Visible = true;
Now for the goodies. You have specified an
OnItemDataBound method in your front end code, so it is time to own up to your promise and provide the method for your fickle and whiny front end code:
protected void AreaResults_ItemDataBound(object sender,
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
Repeater tempRpt =
if (tempRpt != null)
Repeater looks much more manageable and elegant to me now!