Search code examples
asp.netajaxgridviewasyncfileupload

Use AsyncFileUpload in a grid view in update panel


I want to use a AsyncFileUpload in a grid view and each record must have a AsyncFileUpload individually. In addition user must be able to upload his/her file for each record. Now how can i access AsyncFileUpload in the grid view and check it if it has a file or not? For common file upload i have used the below cod:

((FileUpload)GridView1.Rows[idx].Cells[0].FindControl("FileUpload1") as FileUpload).HasFile

However, it is not acceptable in this situation. Is there any way to access this Ajax controller in a grid view?


Solution

  • on your asyncfileupload bind OnUploadedComplete event to the method

    OnUploadedComplete = "FileUploded"
    

    code:

    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();       
    }