enter image description here

whats the problem?

123 should be with bild1.gif and second image with bild2.gif

  • Duplicate of this one: sharepoint.stackexchange.com/questions/57792/… – Nadeem Yousuf Jan 24 '13 at 9:34
  • yea i know , but noone is helping me – Batistuta Jan 24 '13 at 9:35
  • 1
    That is no reason to add another question - it just reduces the value of the site while annoying the people who might be able to help you. Please edit your original question to improve it if you want to increase the chance of getting an answer. – SPDoctor Jan 24 '13 at 13:06

took me some time to understand what you were looking for lol bad on my part but i think i have the right solution for you ;) I've gone through and come up with this code, this link helped me to figure out what was going on :)


ok i think this should work for you

    SPQuery query = new SPQuery();
    query.Query = string.Format("<OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy>");
    query.RowLimit = 10;
    query.IncludeAttachmentUrls = true;
    SPListItemCollection items = list.GetItems(query);

    Repeater1.DataSource = items;

that is fine and is called after the databound, so its doing the binding and then adding thoes links. To ammend the data whilst its being bound you need to call the itemdatabound event like so:

private List<string> arrayList = new List<string>;

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) 
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
          HyperLink hp;
          foreach (SPListItem item in list.Items)

              foreach (string currentAttachmentUrl in item.Attachments)
                  if (!arrayList.Contains(currentAttachmentUrl)) 
                      hp = new HyperLink(); 
                      hp.ID = e.Item.ItemIndex.ToString(); 
                      hp.Text = item.Attachments.UrlPrefix + currentAttachmentUrl; 
                      hp.NavigateUrl = item.Attachments.UrlPrefix + currentAttachmentUrl; 

        // add to the repeater 



to call the event above you need to add this to the repeater:

<asp:Repeater ID="Repeater1" OnItemDataBound="Repeater1_ItemDataBound" runat="server">

I've taken the code that I've done and added it into the new event, your calling the new event where you create the repeater. This should do the trick :)


I've just amended the code above, it checks the current item in the repeater against the current item in the list, if its the same than it will do the code (hyperlink), please let me know the result as you might need to tweak the if function as i dont know what the two values are weather e.Item.ItemIndex starts at 0 or 1 and same with the other :)

hope it helps :)

  • When you add the first news with attachment, it doesnt show it in the interface. When you create a second one, the second one doesn't show up, but the first appears. And when you create a third news, third one doesnt show, but the second and first ones attachment appears. BUT(!). The itemid doesnt following the current news – Batistuta Jan 24 '13 at 23:54
  • iv ammended the code, you need to check the values by debugging the line if (e.Item.ItemIndex == item.ID-1) and see what values are going in. i put -1 as i belive the item.id starts at 1 rather than 0 like the index msdn.microsoft.com/en-us/library/… – Ali Jafer Jan 25 '13 at 8:56
  • With -1 it show ok But the attachment doesn't follow with the uploaded values. it only stays in place For example Name:Martin Age:22 Attachment:hello.jpg i want that the attachment to be together with Martin and Age and not only that it will display the attachment – Batistuta Jan 25 '13 at 10:21
  • Namely,attachments ​​do not accompany their news – Batistuta Jan 25 '13 at 10:29
  • item.id starts at 1 its true and index at 0 but the problem is like above here , that the attachment doesnt follow with the added item to list it only stays in place in the interface – Batistuta Jan 25 '13 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.