0

how can i update image in listview in gridview formate using folder path in asp.net in c#?

 protected void UpdateButton_Click(object sender, EventArgs e)
 {
      TextBox ApplicantIdTextBox = (TextBox)RadListView8.FindControl("ApplicantIdTextBox");
      FileUpload photoTextBox = (FileUpload)RadListView8.FindControl("photoTextBox");


      string fileName1 = Path.GetExtension(ApplicantIdTextBox + photoTextBox.FileName);
      string fileSavePath = Server.MapPath("ImageStorage/" + fileName1);
      tblPersonalInfo pi = new tblPersonalInfo();
      pi.photo = fileName1;
      photoTextBox.SaveAs(fileSavePath);

      dbcontext.AddTotblPersonalInfoes(pi);
      dbcontext.SaveChanges();
 }

But it show me error...What can i do?

Server Error in '/HrPayRoll' Application.

Object reference not set to an instance of an object.

4

1 回答 1

0

我会像这样重写它,然后在调试模式下运行它,看看错误在哪一行。您试图applicantIdTextBox用作 a string,尽管我认为这会产生不同的错误:

protected void UpdateButton_Click(object sender, EventArgs e)
{
    TextBox applicantIdTextBox = RadListView8.FindControl("ApplicantIdTextBox") as TextBox;
    FileUpload photoTextBox = RadListView8.FindControl("photoTextBox") as FileUpload;

    if ((applicantIdTextBox != null) && (photoTextBox != null))
    {
        string fileName = Path.GetExtension(applicantIdTextBox.Text + photoTextBox.FileName);
        string fileSavePath = Server.MapPath("ImageStorage/" + fileName);

        tblPersonalInfo personalInfo = new tblPersonalInfo();
        personalInfo.photo = fileName;

        photoTextBox.SaveAs(fileSavePath);

        dbcontext.AddTotblPersonalInfoes(personalInfo);
        dbcontext.SaveChanges();
    }
}
于 2013-09-16T10:04:30.723 回答