Solved

Bind a list of strings to a repeater?

Posted on 2011-03-22
2
741 Views
Last Modified: 2012-05-11
I dont know what property should I use in the EVAL on the repeater

please help

private void LoadCategories()
        {
            BindingList<string> tags = new BindingList<string>();
            using (Entities.EntitiesDataContext dc = new Entities.EntitiesDataContext(SPContext.Current.Site.Url))
            {
                EntityList<Entities.Article> articles = dc.GetList<Entities.Article>("Article");
                List<Entities.Article> listArticles = new List<Entities.Article>();

                var articlesqry = (from row in articles
                                   where row.ItemLanguage.ToString() == (WebPart.Language == null ? DefaultLanguage : Language)
                                   select row).ToList();

                listArticles = (List<Entities.Article>)articlesqry;

                foreach (Entities.Article article in listArticles)
                {
                    SPSite site = SPContext.Current.Site;
                    // get the list
                    SPList lstTagList = site.RootWeb.Lists.TryGetList("Article");
                    if (lstTagList != null)
                    {
                        // Try to find the item I want
                        SPQuery query = new SPQuery();
                        query.Query = "<Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + article.Id + "</Value></Eq></Where></Query>";
                        SPListItemCollection foundItems = lstTagList.GetItems(query);
                        DataView dv = new DataView(foundItems.GetDataTable());
                        string tag = dv[0]["Agenda_x0020_Tags"].ToString().Substring(0, dv[0]["Agenda_x0020_Tags"].ToString().IndexOf("|"));
                        if (!tags.Contains(tag))
                        {
                            tags.Add(tag);
                        }                        
                    }
                }
                CategoryRepeater.DataSource = tags;
                CategoryRepeater.DataBind();

            }


  <ul>
        <asp:Repeater ID="CategoryRepeater" runat="server">
            <ItemTemplate>
                <li>
                    <asp:HyperLink ID="TagLink" runat="server"></asp:HyperLink>    
                </li>
            </ItemTemplate>
        </asp:Repeater>      
    </ul>
0
Comment
Question by:Simbios
2 Comments
 
LVL 7

Accepted Solution

by:
nbove earned 500 total points
ID: 35191975
Since you are not evaluating a specific property of the dataitem, you would just use Container.DataItem

The hyperlink would look like this:
<asp:HyperLink ID="TagLink" runat="server" Text='<%# Container.DataItem %>'></asp:HyperLink>    
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35191978
You don't use Eval, you use Container.DataItem by itself:
<asp:HyperLink ID="TagLink" runat="server"><%# Container.DataItem %></asp:HyperLink> 

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A short film showing how OnPage and Connectwise integration works.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now