Evaluating String Lists in a Repeater

by Steve Bumbaugh 9. November 2008 21:05

ASP.NET has a simple method for binding lists to Repeaters and displaying the properties of items contained within the Repeater.  The Eval function is the mechanism for handling this and finding information on how to do this is pretty easy:

<%# Eval("Property") %>

or

<%# DataBinder.Eval(Container.DataItem, "Property") %>

Where Property is the property to evaluate for the current item within the dataset for the Repeater.

What if you wanted to evaluate the entire Item instead of the property of the item?  Primitive types such as  Strings or Integers would be candidates for this, but this operation can often be confusing if you don't do it frequently enough.  It varys from the common Eval syntax, but is equally simple.

IList<String> tmpStrings = new List<String> { "value1", "value2", "value3" };
rTmp.DataSource = tmpStrings;
rTmp.DataBind();

<Repeater ID="rTmp" runat="server">
    <ItemTemplate>
        <%# (String)Container.DataItem %>
    </ItemTemplate>
</Repeater>

Instead of using Eval to evaluate the property of the current data item, the actual data item is evaluated by using Container.DataItem.

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , ,

Categories: Web Development | C# | .NET


Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



©2010 www.codecarnage.com

Resume

Technical Lead (HTML, PDF)

RecentComments

Comment RSS