主题:请教个问题!各位高手帮帮忙啊!小弟感激不尽!
这是一个多文件上传的代码:
前台是这样:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upflie.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 612px"><tr><td style="width: 608px; text-align: center;">
<asp:Button ID="Button1" runat="server" Text="上传文件" OnClick="Button1_Click" /></td></tr><tr><td style="width: 608px; text-align: center;">
<asp:Button ID="Button2" runat="server" Text="添加文件" OnClick="Button2_Click" /></td></tr><tr><td style="width: 608px; height: 21px; text-align: center;">
<asp:Button ID="Button3" runat="server" Text="查看信息" OnClick="Button3_Click" /></td></tr><tr><td style="width: 608px; height: 21px; text-align: center;">
<table id="F" enableviewstate="true" cellpadding="0" cellspacing="0"><tr>
<td style="width:249px"><asp:FileUpload ID="FileUpload1" runat="server" />
</td></tr></table></td></tr></table>
</div>
</form>
</body>
</html>
里面有表格我设id为F了
在后台:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)//首次执行页面
{
SFUPC();//页面执行一次将上传文件控件集到缓存中
}
}
protected void Button2_Click(object sender, EventArgs e)
{
InserC();
}
protected void Button1_Click(object sender, EventArgs e)
{
UpFile();
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("Info.aspx");
}
private void SFUPC()
{
ArrayList AL = new ArrayList();
foreach (Control C in F.Controls)/////就这里错:他说(当前上下文中不存在名称“F”)我已经在前台设表格id为F了!是怎么回事啊?我是刚学的!不怎么会!哎!烦恼啊!!!
{
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;
AL.Add(FU);
}
}
}
}
Session.Add("FilesControls", AL);
}
错误是这样:
当前上下文中不存在名称“F”
前台是这样:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upflie.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 612px"><tr><td style="width: 608px; text-align: center;">
<asp:Button ID="Button1" runat="server" Text="上传文件" OnClick="Button1_Click" /></td></tr><tr><td style="width: 608px; text-align: center;">
<asp:Button ID="Button2" runat="server" Text="添加文件" OnClick="Button2_Click" /></td></tr><tr><td style="width: 608px; height: 21px; text-align: center;">
<asp:Button ID="Button3" runat="server" Text="查看信息" OnClick="Button3_Click" /></td></tr><tr><td style="width: 608px; height: 21px; text-align: center;">
<table id="F" enableviewstate="true" cellpadding="0" cellspacing="0"><tr>
<td style="width:249px"><asp:FileUpload ID="FileUpload1" runat="server" />
</td></tr></table></td></tr></table>
</div>
</form>
</body>
</html>
里面有表格我设id为F了
在后台:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)//首次执行页面
{
SFUPC();//页面执行一次将上传文件控件集到缓存中
}
}
protected void Button2_Click(object sender, EventArgs e)
{
InserC();
}
protected void Button1_Click(object sender, EventArgs e)
{
UpFile();
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("Info.aspx");
}
private void SFUPC()
{
ArrayList AL = new ArrayList();
foreach (Control C in F.Controls)/////就这里错:他说(当前上下文中不存在名称“F”)我已经在前台设表格id为F了!是怎么回事啊?我是刚学的!不怎么会!哎!烦恼啊!!!
{
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;
AL.Add(FU);
}
}
}
}
Session.Add("FilesControls", AL);
}
错误是这样:
当前上下文中不存在名称“F”