Repeater asp.net tag not working

Paolo William Siviero

I have a problem with the Repeater tag of ASP.NET. It simply doesn't generate the html code when the page is running. I'm trying to use it to generate a list of tag for a slideshow, here is the asp code:

<asp:Repeater id="foto" runat="server">
<ItemTemplate>
<img src='<%# (string)Container.DataItem %>'/>
</ItemTemplate>
</asp:Repeater>

And here is the code behind:

protected void Page_Load(object sender, EventArgs e)
{    
    if (IsPostBack)
    {
        int num = Directory.GetFiles(@"C:\Users\Paolo\Desktop\Podisti\Slideshow\" + Request.QueryString["Cartella"]).Length;
        List<string> elencoUrl = new List<string>();
        for (int i = 1; i <= num; i++)               
            elencoUrl.Add(@"Slideshow\" + Request.QueryString["Cartella"] + "00" + i + "_jpg.jpg");
        foto.DataSource = elencoUrl; //può essere ad esempio un Array o una List di stringhe
        foto.DataBind();
    }
}

EDIT: Thank you for the answer, even if it isn't the solution of the problem: the page i've created is only a test which, with the click of 2 linkbuttons, redirect to the same page with a different querystring so that the repeater can create different src attributes for the img tag every time. The postback is in here only to prevent an error in the first load of the page (where the querystring is null), I will changed it when I will solve this problem.

The main problem is that the repeater doesn't do its work, if i check the code of the page during its execution:

   <div style="width:500px;height:400px">        
    <div class="fotorama">
        /*The repeater doesn't create the <img> tags*/
    </div>             
</div>
walther
if (IsPostBack)

means your code will be executed only if you just posted back the page, but you probably want to show it as a default, not during a postback. Fix it to:

if (!IsPostBack)

if that's the case.

Also, you should never try to reach outside your web app folder to get folders/files, because those won't be accessible on the server. Never hardcode paths like this!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

asp.net - Create contatenated href tag in a repeater element

From Dev

asp.net - Create contatenated href tag in a repeater element

From Dev

<a> tag not repeating correctly in asp:repeater

From Dev

OnItemCommand of asp:Repeater not working with validator

From Dev

Anchor tag not working properly in asp.net

From Dev

Using foreach with ASP.NET view engine inside a ASP: Repeater is not working

From Dev

NavigateUrl on Repeater ASP.net

From Dev

NavigateUrl on Repeater ASP.net

From Dev

Sharepoint master page asp:repeater tag

From Dev

asp.net vnext Tag helpers select option not working

From Dev

ASP.NET Repeater - Eval() for bool?

From Dev

Convert Bootstrap Carousel to ASP.Net Repeater

From Dev

ASP .NET Using a Repeater inside of UpdatePanel with UpdateProgress

From Dev

asp.net repeater for each row

From Dev

repeater item command in asp.net

From Dev

to disable a label of repeater on some condition in asp .net

From Dev

Using Bootstrap tabs with ASP NET repeater

From Dev

asp.net repeater use template in javascript

From Dev

To bind images in repeater using asp.net

From Dev

asp.net repeater merge columns dynamically

From Dev

Fix header row in repeater in ASP.NET

From Dev

ASP.NET Converting repeater item to the textbox

From Dev

asp.net repeater merge columns dynamically

From Dev

Convert Bootstrap Carousel to ASP.Net Repeater

From Dev

Conditional statement for Repeater Controll in ASP.NET

From Dev

Fix header row in repeater in ASP.NET

From Dev

trying Image Button in repeater Asp.net

From Dev

asp net dropdown selectedvalue/selectedindex not updating in repeater

From Dev

ASP.Net - Issues with Repeater / DataBinding

Related Related

HotTag

Archive