0

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?

Saeid
  • 1,996
  • 4
  • 27
  • 44

1 Answers1

1

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();       
}
voddy
  • 950
  • 1
  • 11
  • 21
  • Thank you, But i need the following code there too: sqlcmd.Parameters.AddWithValue("@Upload", "~/InputReviewer/" + MainFileName) For that i need idx which i should extract it from command button. I need to extract idx from table and save the upload file within a it's ID in the database. Is there any way? – Saeid Mar 10 '14 at 06:00
  • 1
    I updated the code with how to get row index. You can extract any value in any column this way. – voddy Mar 10 '14 at 07:37
  • Thank you. Just two problems: 1- ctype is not recognizable! Dose it need any namespace? 2- How should i write this code in C# language: Dim fu AjaxControlToolkit.AsyncFileUpload – Saeid Mar 10 '14 at 07:43
  • Only one more thing please, as i mentioned ctype and AsyncFileUpload is not recognizable in behind cod! Do they need a name space? – Saeid Mar 10 '14 at 08:05
  • CType is vb.net so if you are with c#, forget it. and include this in your xaml: <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %> use ajax as prifix in xaml – voddy Mar 10 '14 at 08:09
  • Thank you so much, dose CType has any alternative in C#? – Saeid Mar 10 '14 at 08:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/49380/discussion-between-voddy-and-saeed-talaee) – voddy Mar 10 '14 at 08:18
  • Is there any way that all these happen when i click on a button in grid view? – Saeid Mar 10 '14 at 08:41
  • As i used it in command button, it gave me the following error: Unable to cast object of type 'System.Web.UI.WebControls.Button' to type 'AjaxControlToolkit.AsyncFileUpload'. – Saeid Mar 10 '14 at 09:37
  • I have just posted it. – Saeid Mar 10 '14 at 09:48