SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I am returning items from a SharePoint list is there anyway that I can store the values in an array or a list to use them in an ASP Repeater? I would have 4 values that would need to be stored (the List has 4 columns) and random numbers of records (rows) that would be returned. Is there any way to accomplish this?

            using (SPSite site = new SPSite("MYSITE"))
                    using (SPWeb oWebsiteRoot = site.OpenWeb())
                        SPList oList = oWebsiteRoot.Lists["SInfo"];
                        SPListItemCollection items = oList.Items;

                        foreach (SPListItem listitem in items)
                            //ADD 4 Items to an array or List
share|improve this question
up vote 5 down vote accepted


Repeater.DataSource = oList.Items.GetDataTable();

Should do the trick.

share|improve this answer
I tried that but when I try to access my page I get an error DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Market'. when I just used the line Market: <%# Eval("Market") %> <br /> Why cant I reference my column market? – atrljoe Aug 10 '11 at 18:12
Did you inspect the table to see what columns it contains? You may also want to use GetListItems with a query to only return the columns you want, especially if you have a lot of columns on the list and/or a lot of items. – Rob D'Oria Aug 10 '11 at 18:26
I know it's been almost a year, but it helped me today! +1 from me. To display the desired column, I used the following: <%# DataBinder.Eval(Container.DataItem, "column-name") %> – utkai Jul 10 '12 at 9:23
+1 from me, it helped me! – Anuja Nov 26 '12 at 10:45

you can not use Eval("Market") because SPListItem does not have any property called Market.

what you can do is something like that:

<%# ((SPListItem)Container.DataItem)["Market"] %>

You will just need to import the SharePoint assembly in your page :

<%@ Import Namespace="Microsoft.SharePoint" %>   
<%@ Assembly Name=""Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"" %> 

EDIT : it applies only if you had bind the SPListItemCollection directly without using the GetDataTable() method

share|improve this answer

I used this and working fine

<%# ((SPListItem)Container.DataItem)["FieldName"] %>
share|improve this answer

It's better to pass entity object to your repeater exemple :

public class MyEntity
   public string Title { get; set; }
   public string Description { get; set; }

System.Collections.Generic.List<MyEntity> MyRepeaterBind(SPListItemCollection collection)
   List<MyEntity> items = new List<MyEntity>();
   foreach (SPListItem item in collection)

      items.Add(new MyEntity
         Title = Convert.ToString(item["your title column here"]),
         Description = Convert.ToString(item["your description column here"])
   YourRepeater.DataSource = items;

In your asp just use <%# Eval("Title") %> <%# Eval("Decription") %>

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.