我正在尝试创建一个页面,该页面具有可变数量的 FileUpload 字段,具体取决于用户从下拉列表中选择的数量。
我的 .apsx 代码如下;
<tr>
<td>Number of photo's to upload</td>
<td><asp:DropDownList ID="DLPhotoCount" runat="server" OnSelectedIndexChanged="OnSelectedIndexChanged_PhotoCount" AutoPostBack="true">
<asp:ListItem Text="..."></asp:ListItem>
<asp:ListItem Text="1"></asp:ListItem>
<asp:ListItem Text="2"></asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td>Picture 1:</td>
<td><asp:FileUpload runat="server" ID="Pic1" Visible="false"/></td>
</tr>
<tr>
<td>Picture 2:</td>
<td><asp:FileUpload runat="server" ID="Pic2" Visible="false"/></td>
</tr>
<tr>
<td><asp:Button runat="server" ID="BtnUploadFiles" text="Upload Files" OnClick="OnClick_BtnUploadFiles" Visible="false"/></td>
</tr>
我的 C# 是;
protected void OnSelectedIndexChanged_PhotoCount(object sender, EventArgs e)
{
string Pic = "Pic";
int PicNo = Convert.ToInt32(DLPhotoCount.SelectedItem.Text);
if (DLPhotoCount.SelectedItem.Text != "...")
{
string StPicNo = Pic + PicNo;
do
{
FileUpload StPicNo.Visible = true;
PicNo = PicNo + 1;
}
while (PicNo < Convert.ToInt32(DLPhotoCount.SelectedItem.Text + 1));
BtnUploadFiles.Visible = true;
}
else
{
Pic1.Visible = false;
Pic2.Visible = false;
BtnUploadFiles.Visible = false;
}
}
如果这不是实现所需功能的最佳方式,请接受有关任何替代方案的建议