Solved

Bind a list of strings to a repeater?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 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