Solved

Bind a list of strings to a repeater?

Posted on 2011-03-22
2
738 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

22 Experts available now in Live!

Get 1:1 Help Now