Advertise with us

Adressing a fileupload within a repeater

Posted by  Simons Hood
 2409  View(s)
Rate this:

i have my fileupload within my repeater

  <asp:Content ID="Content3" ContentPlaceHolderID="content" Runat="Server">

<asp:Repeater ID="rptVrijstellingen" runat="server">



        <h2><%# Eval("tblExternVak.ExternvakNaam") %></h2>

        <h4>Selecteer een bestand om te uploaden:</h4>

       Gelieve het bestand de naam te geven van het overeenkomstige vak om de verwerking

           vlot te laten verlopen.

           <br /><br />  <br />

           <asp:FileUpload id="FileUpload1"                



       <br /><br />

       <hr />

       <br />

         <br />

        <asp:Button id="UploadButton"

           Text="Upload file"




       <br />   

    <br />


        <SeparatorTemplate><hr /></SeparatorTemplate>


       <asp:CheckBox id="CBupload" runat="server" />

       <asp:Label id="lblUpload" runat="server"> Geleverd aan Mevrouw Van Orlé</asp:Label>

       <asp:Label id="UploadStatusLabel" runat="server" ForeColor="Red"></asp:Label>  


And i want to adress it from my classfile

   if (FileUpload1.HasFile)




            String fileName = FileUpload1.FileName;

            savePath += fileName;


            tblBijlage s = new tblBijlage();

            s.bijlageTitel = fileName;

            s.bijlageURL = savePath;

            s.bijlageType = "1";

            s.fk_externvakID = 2;

            BLLstudent BLLstudent = new BLLstudent();



        catch (Exception ex)


            UploadStatusLabel.Text = ex.Message;





      UploadStatusLabel.Text = "Gelieve een bestand te kiezen";




The problem is it doesnt find fileupload1 and any other declared stuff within the repeater, can anyone present me a solution on how to adress the upload within the repeater? (I fill up the repeater with data in my page_load so it exists on load so i know that is not the problem)

Thank you in advance 

  1. Re: Adressing a fileupload within a repeater

    Hi Samuel, 

    You have to iterate the Items collection of Repeater control and use FindControl method to get the reference of FileUpload1 object.

    foreach (RepeaterItem item in rptVrijstellingen.Items)
        FileUpload file=(FileUpload)item.FindControl("FileUpload1");
        String fileName = file.FileName;
        FileUpload1.SaveAs(Server.MapPath(savePath + fileName));

      Modified On Apr-05-2018 04:11:49 AM