ListViewInsertEventArgs에 대해 e.Values 메서드를 참조 할 때 linq 및 listview 컨트롤을 사용하여 이미지를 데이터베이스에 업로드 할 수 있지만 ?대신 e.Values.add (... 대신 ListViewEditEventArgs를 사용하여 이미지를 업로드 할 수 있습니다.
보호 무효 ProjectPhotosList_ItemInserting (개체를 보낸 사람, ListViewInsertEventArgs 전자)
{
다음 ListViewEditEventArgs에서 그러한 방법이 없다, 그래서 동일한 결과를 달성하기 위해 사용할 수있는 여기 내 삽입 코드FileUpload uplImage = (FileUpload) ProjectPhotosList.InsertItem.FindControl ("uplImage");
레이블 fileuploadlbl = (레이블) ProjectPhotosList.InsertItem.FindControl ("fileuploadlbl");
byte[] img = null;
if (uplImage.HasFile || !uplImage.FileName.ToLower().EndsWith(".jpg"))
{
try
{
img = new byte[uplImage.PostedFile.ContentLength];
uplImage.PostedFile.InputStream.Read(img, 0, img.Length);
}
catch
{
fileuploadlbl.Text = "unable to upload " + uplImage.FileName.ToString();
}
}
if (img == null)
{
e.Cancel = true;
fileuploadlbl.Text = "Please choose a file to upload";
}
try
{
e.Values.Add("ProjectPhoto", new System.Data.Linq.Binary(img));
fileuploadlbl.Text = "File Upload Successful";
}
catch
{
fileuploadlbl.Text = "File Upload Failed, please try again";
}
}