Solved

Bind a list of strings to a repeater?

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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