//该方法用于添加一个上传文件的控件
private void InsertC()
{
//实例化ArrayList
ArrayList AL = new ArrayList();
this.F.Rows.Clear(); //清除id为F表格里的所有行
GetInfo();
//表示 HtmlTable 控件中的 <tr> HTML 元素
HtmlTableRow HTR = new HtmlTableRow();
//表示 HtmlTableRow 对象中的 <td> 和 <th> HTML 元素
HtmlTableCell HTC = new HtmlTableCell();
//在单元格中添加一个FileUpload控件
HTC.Controls.Add(new FileUpload());
//在行中添加单元格
HTR.Controls.Add(HTC);
//在表中添加行
F.Rows.Add(HTR);
Sfupc();
}
//该方法用于将保存在Session中的上传文件控件集添加到表格中
private void GetInfo()
{
ArrayList AL = new ArrayList();
if (Session["FilesControls"] != null)
{
AL = (ArrayList)Session["FilesControls"];
for (int i = 0; i < AL.Count; i++)
{
HtmlTableRow HTR = new HtmlTableRow();
HtmlTableCell HTC = new HtmlTableCell();
HTC.Controls.Add((System.Web.UI.WebControls.FileUpload)AL[i]);
HTR.Controls.Add(HTC);
F.Rows.Add(HTR);
}
}
}
//该方法用于当前页面上传文件控件集保存到Session中
private void Sfupc()
{
ArrayList AL = new ArrayList();//创建动态增加数组
foreach (Control C in F.Controls)
{
//在表格中查找出FileUpload控件添加到ArrayList中
if (C.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlTableRow")
{
HtmlTableCell HTC = (HtmlTableCell)C.Controls[0];
foreach (Control FUC in HTC.Controls)
{
if (FUC.GetType().ToString() == "System.Web.UI.WebControls.FileUpload")
{
FileUpload FU = (FileUpload)FUC;
//添加FileUpload控件
AL.Add(FU);
}
}
}
}
//把ArrayList添加到Session中
Session.Add("FilesControls", AL);
}