如何以gridview格式更新listview中的图像?

时间:2013-09-16 09:39:16

标签: c# asp.net

如何使用c#中的asp.net中的文件夹路径更新gridview formate中listview中的图像?

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

但它告诉我错误......我该怎么办?

  

'/ HrPayRoll'应用程序中的服务器错误。

     

对象引用未设置为对象的实例。

1 个答案:

答案 0 :(得分:0)

我会重写它,然后在调试模式下运行它,看看错误在哪一行。您试图将applicantIdTextBox用作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();
    }
}