I was told to use a Repeater control in what I am doing which is a “Data Entry” screen with ASP.NET controls -a standard “address” like form. In cases, the fields on the form will repeated twice, once for the original values, one for the changed values. I have not used this control before but it seems like I have to bind to a database. Instead, I have an Entity object that has been obtained via a Repository. Can I bind to an object like this?
[DataContract()]
public class RON
{
[DataMember]
public string Id { get; set; }
[DataMember]
public string Comments { get; set; }
Then, I have my ASP.NET fields which I used the following with CSS to get the fields to line up. Can I put this in an ItemTemplate?
<div class="row1">
<div class="label">
ID:
</div>
<div class="value">
<asp:Label ID="lblId" runat="server" />
</div>
You will likely want to do something in your PageLoad such as:
You then can bind your entity object collection to the repeater control using the DataSource property of the repeater control.
Then by calling DataBind on that control, your collection will become bound to that control.
Then all you need to do is use the Repeater’s databound event to apply your custom properties to the repeater’s controls.
The ItemDataBound event will be called for each row item, so each time it is called you will be working on the that row item’s controls and databound object.
An alternative approach would be to directly databind within markup, not using the OnItemDataBound event.
The direct cast avoids the call into DataBinder.Eval, and the overhead of reflection.