所以我在我的转发器中有我的文件上载
<asp:Content ID="Content3" ContentPlaceHolderID="content" Runat="Server">
<asp:Repeater ID="rptVrijstellingen" runat="server">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<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"
runat="server">
</asp:FileUpload>
<br /><br />
<hr />
<br />
<br />
<asp:Button id="UploadButton"
Text="Upload file"
OnClick="UploadButton_Click"
runat="server">
</asp:Button>
<br />
<br />
</ItemTemplate>
<SeparatorTemplate><hr /></SeparatorTemplate>
</asp:Repeater>
<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>
</asp:Content>
我想从我的类文件中找到它
if (FileUpload1.HasFile)
{
try
{
String fileName = FileUpload1.FileName;
savePath += fileName;
FileUpload1.SaveAs(Server.MapPath(savePath));
tblBijlage s = new tblBijlage();
s.bijlageTitel = fileName;
s.bijlageURL = savePath;
s.bijlageType = "1";
s.fk_externvakID = 2;
BLLstudent BLLstudent = new BLLstudent();
BLLstudent.insertFile(s);
}
catch (Exception ex)
{
UploadStatusLabel.Text = ex.Message;
}
}
else
{
UploadStatusLabel.Text = "Gelieve een bestand te kiezen";
}
}
}
问题是它没有在转发器中找到fileupload1和任何其他声明的内容,是否有人可以向我提供如何在转发器中添加上传的解决方案? (我用page_load中的数据填充转发器,所以它存在于加载状态,所以我知道这不是问题)
提前谢谢你:)
答案 0 :(得分:3)
您必须迭代Repeater控件的Items集合并使用FindControl
方法获取FileUpload1
对象的引用。
foreach (RepeaterItem item in rptVrijstellingen.Items)
{
FileUpload file=(FileUpload)item.FindControl("FileUpload1");
String fileName = file.FileName;
FileUpload1.SaveAs(Server.MapPath(savePath + fileName));
....
}
答案 1 :(得分:0)
使用rptVrijstellingen.Items[rowNumber].FindControl("FileUpload1") as FileUpload
,其中rowNumber
是您要访问的行数。