如何从网格视图中的FileUpload获取图像的路径名

时间:2017-03-07 12:02:39

标签: asp.net

你好我在gridview中有我的FileUpload.I上传每一行的图像,然后点击名为UPLOAD的按钮。因此它应该从每一行获取图像路径并上传。 UPLOAD的Onclick监听器是UploadBtn_onClickUploadBtn_onClick的代码是

protected void UploadBtn_onClick(object sender, EventArgs e)
        {
            foreach (GridViewRow row in StudentGrid.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    try
                    {
                        UpdateEmailProperties objUpdateEmailId = new UpdateEmailProperties();

                        GridViewRow grdrow = (GridViewRow)((FileUpload)sender).NamingContainer;
                        FileUpload filename = (FileUpload)grdrow.Cells[5].FindControl("fileuploadimages");


                        objUpdateEmailId.StudId =  int.Parse(row.Cells[6].Text);
                        objUpdateEmailId.Email = row.Cells[3].Text;
                        objUpdateEmailId.profilepath = "profilepics/" + filename;

                        int intStatus;
                        intStatus = Stud.UpdateStudentEmailId(objUpdateEmailId);
                        if (intStatus != 0)
                        {
                            lblWarning.Text = "Updated successfully";
                        }
                        else
                        {
                            lblWarning.Text = "Failed to Update";
                        }
                    }
                    catch (Exception ex)
                    {
                        //LogFile.CreateLog("User", "AddPlacement", ex.Message);
                        lblWarning.Text = "Error: " + ex.Message.ToString();

                    }
                }
            }
        }

但我的错误是

Unable to cast object of type 'System.Web.UI.WebControls.Button' to type 'System.Web.UI.WebControls.FileUpload'

I need to fetch name of file returned from loadfile

I need to fetch name of file returned from loadfile

0 个答案:

没有答案