Solved

Bind a list of strings to a repeater?

Posted on 2011-03-22
2
751 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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