在详细视图中,我有用户控件,我喜欢用
填充其中的内容foreach (var file in fileList.Efiles)
但是我有(fileList.Efiles)错误“对象引用不设置对象的实例”
请帮助解决问题
完整的代码如下:
public partial class DocResult : System.Web.UI.Page
{
private EDMSDataContext _DataContext;
private int _TransmittalId;
private int _DocId;
protected void Page_Load(object sender, EventArgs e)
{
String tmpString1;
String tmpString2;
tmpString1 = Request.QueryString["DocId"];
if (String.IsNullOrEmpty(tmpString1))
throw new ArgumentNullException("DocId");
_DocId = Convert.ToInt32(tmpString1);
tmpString2 = Request.QueryString["TransID"];
if (String.IsNullOrEmpty(tmpString2))
throw new ArgumentNullException("TransID");
_TransmittalId = Convert.ToInt32(tmpString2);
_DataContext = new EDMSDataContext();
var query = _DataContext.spDocResult(_DocId, _TransmittalId);
DetailsView1.DataSource = query.ToList();
DetailsView1.DataBind();
spDocResultResult docresult = (spDocResultResult)DetailsView1.DataItem;
FileTemp fileList = (FileTemp)DetailsView1.FindControl("FileTemp1");
foreach (var file in fileList.Efiles)
{
file.FileName = docresult.Filename;
}
fileList.DataBind();
}
}
答案 0 :(得分:0)
尝试以下代码
if(fileList!=null)
{
foreach (var file in fileList.Efiles)
{
file.FileName = docresult.Filename;
}
fileList.DataBind();
}