Gridview with FileUpload control

I have a gridview that shows an image as part of one of its columns. In edit mode, I want the user to be able to upload a new image file, so I use the FileUpload control in the template editing part.

I have an event to fix this, I believe:

        protected void GridVew1_RowUpdated(object sender, GridViewUpdateEventArgs e)
    {          
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("images/hardware/" + FileUpload1.FileName));
        }
    }

I don’t know how to call the control correctly, how ... How is this functionality encoded?

+3
source share
2 answers

RowUpdating RowUpdated. FileUpload .

: , . 0, , . Cells .

protected void gridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = gridView.Rows[e.RowIndex];
    FileUpload fileUpload = row.Cells[0].FindControl("fileUpload1") as FileUpload;
    if (fileUpload != null && fileUpload.HasFile)
    {
        fileUpload.SaveAs(Server.MapPath("images/hardware/" + fileUpload.FileName));
    }
}
+4

, ,

VB -

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating

      Dim aRow As GridViewRow = Me.GridView1.Rows(e.RowIndex)

    dim xFileUpload as fileupload = CType(aRow.FindControl("FileUpload1"), FileUpload)

    xFileUpload. save file etc etc etc 

End Sub 

- , , !

+1

Source: https://habr.com/ru/post/1707001/


All Articles