我想在网格视图中使用AsyncFileUpload,并且每个记录必须单独具有AsyncFileUpload。此外,用户必须能够为每条记录上传他/她的文件。 现在我如何在网格视图中访问AsyncFileUpload并检查它是否有文件? 对于常见的文件上传,我使用了以下鳕鱼:
((FileUpload)GridView1.Rows[idx].Cells[0].FindControl("FileUpload1") as FileUpload).HasFile
然而,在这种情况下是不可接受的。 有没有办法在网格视图中访问此Ajax控制器?
答案 0 :(得分:1)
在asyncfileupload上将OnUploadedComplete事件绑定到方法
OnUploadedComplete = "FileUploded"
代码:
protected Sub FileUploded(object sender, EventArgs e)
Dim fu AjaxControlToolkit.AsyncFileUpload
Dim row As GridViewRow = CType(fu.NamingContainer, GridViewRow)
Dim idx = row.RowIndex
fu = ctype(sender,AjaxControlToolkit.AsyncFileUpload)
If fu.HasFile then
--do something--
End If
End Sub
C#:
protected void FileUploded(object sender, EventArgs e)
{
AsyncFileUpload fu = (AjaxControlToolkit.AsyncFileUpload)sender;
GridViewRow row = (GridViewRow)fu.NamingContainer;
string idx = row.RowIndex.toString();
}