0

I'm currently trying to figure out a way to display a dynamic number of icons on a page. I have a String array with my image urls.

The way the page is set up currently is that a few different attributes are set up through a repeater (name, title etc.) and I would like to add a dynamic number of images to each of these sections.

For example, row 1 may have 3 images where as row 2 may have 1.

Could anyone recommend a method to do this? I looked into picturebox but I apparently don't have the correct header files for that on this system.

Thanks!

Edit:

Ive actually got the header files for Picturebox working (I think) so if anyone has a good solution for using that that would also be appreciated!

Patt
  • 31
  • 3
  • 2
    If you're using asp.net, why can't you just use the html img tag? –  Mar 16 '15 at 16:30
  • I have an array in C# that populates depending on the row of data I'm pulling. I'm not sure what you mean as the number of images displayed will be different each time – Patt Mar 16 '15 at 16:40
  • 1
    can you post your code? whats the problem with just writing img tags? – Ewan Mar 16 '15 at 16:41
  • My current code doesn't have much in terms of this problem, I'm more so looking for a logical solution to the problem. There's no problem with doing that, except the number of images are dynamic depending on what information is displayed (could be 2 images, could be 200); I don't necessarily want to write a static number of img tags in my asp, unless you're referring to something else? – Patt Mar 16 '15 at 18:32

2 Answers2

0

You can always try using JQuery and AJAX, in the C# code, have a method which returns your array as a JSON. You can then use AJAXto call the JSON and you can append the data returned to create html img elements in your page.

How to return JSon object

http://api.jquery.com/append/

http://api.jquery.com/jquery.ajax/

Community
  • 1
  • 1
  • odds on picture box being some jquery add on the OP cant get working? – Ewan Mar 16 '15 at 16:44
  • PictureBox is a Windows Forms control while repeater was used extensively in the pre-MVC days. I suspect it's the OP's first time using ASP.NET and HTML and/or this is an attempt to port desktop code to ASP.NET – Panagiotis Kanavos Mar 16 '15 at 16:47
0

You can use a repeater within a repeater.

If the list of images is a property of your outer repeater item you can bind to that declaratively:

<asp:Repeater id="outer" runat="server" DataSource="MyItems">
    <ItemTemplate>
        <asp:Repeater id="images" runat="server" DataSource=<%# ((string)Container.DataItem).Split(',') %>>
            ...
    </ItemTemplate>
</asp:Repeater>

You can also bind data during the approprate ItemBinding event (can't remember what it's called).

Mark Rabjohn
  • 1,643
  • 14
  • 30
  • Thanks for the reply. This is my first time working with repeaters, so forgive me for my ignorance. Do I need to bind the nested repeater within the DataBind method of the outer repeater instead of the pageload? When I do the above, it cant find the nested repeater since it's not called yet. I'm not sure how to do this – Patt Mar 16 '15 at 18:07
  • Hey, just commenting to say that I ended up getting the nested repeater to work. I wasn't aware at first that you had to do a findcontrol on the nested repeater within the databind method of the outer repeater. Once i did that and bound the nested data, it worked like a charm. Thanks! – Patt Mar 17 '15 at 15:18
  • The partial example I put in should have allowed you to bind to the data declaratively via the DataSource property. Using the event is more useful if you need to grab the data from a database, or possibly makes more sense if you already have an event for other reasons (like configuring controls). I wonder could you click 'correct answer' or at least upvote? My SO score is dismal :( – Mark Rabjohn Mar 18 '15 at 10:48