Je la déclaration LINQ suivanteAccès aux objets dans un datalist par Linq
from DataListItem dli in dlAttachments.Items
select new Objects.BHAttachment
{
Name = ((FileUpload)dli.FindControl("fuAttachment")).HasFile ? ((FileUpload)dli.FindControl("fuAttachment")).FileName : (((HyperLink)dli.FindControl("hypCurrentAttachment")).Text != null ? ((HyperLink)dli.FindControl("hypCurrentAttachment")).Text : ""),
Path = ((FileUpload)dli.FindControl("fuAttachment")).HasFile ? ((FileUpload)dli.FindControl("fuAttachment")).PostedFile.FileName : "",
FileUpload = ((FileUpload)dli.FindControl("fuAttachment")).HasFile ? ((FileUpload)dli.FindControl("fuAttachment")) : new FileUpload(),
DocumentType = ((Label)dli.FindControl("lblType")).Text,
URL = ""
}
Et ça marche très bien. Ma question concerne la re-référence constante de l'objet FileUpload. Je recréais (et je le relis) 6 fois. Y at-il un moyen de le définir une fois dans Linq et se référer à cet objet unique?
OOoooooooo :-D Merci !! –
Vos parenthèses sont désactivées ... "(" avant x.FileName n'est pas approprié ... –