IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

Problème avec une éval de Container on databinding


Sujet :

ASP.NET

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 74
    Points : 55
    Points
    55
    Par défaut Problème avec une éval de Container on databinding
    Bonjour à tous !
    Je rencontre un problème lors de l'évaluation d'une donnée de container.
    Hop un petit morceau de code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <TD align="left" vAlign="top" align="center" width="124px">
    <% if (DataBinder.Eval(Container, "DataItem.id_Fichier").ToString().Substring(0, 2) == "DLG")
    {%>
    <asp:HyperLink id=Hyperlink2 runat="server" width="124px" Text='<%# DataBinder.Eval(Container, "DataItem.id_Fichier") %>' Font-Underline="True" CssClass="bleu" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.id_Fichier", "http://jeanlutz.dyndns.org/download/micro/{0}.maj") %>'></asp:HyperLink>
    <% }
    else
    { %>
    <asp:HyperLink id=Hyperlink1 runat="server" width="124px" Text='<%# DataBinder.Eval(Container, "DataItem.id_Fichier") %>' Font-Underline="True" CssClass="bleu" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.id_Fichier", "http://jeanlutz.dyndns.org/download/micro/{0}.exe") %>'></asp:HyperLink>
    <% } %>
    </TD>
    Vla en gros, ce que je veux faire, c'est attribuer un lien différent selon la valeur de DataBinder.Eval(Container, "DataItem.id_Fichier").

    Lors du build j'ai ce message d'erreur
    Le nom 'Container' n'existe pas dans le contexte actuel
    qui correspond à la condition du If.
    Ce que je pense avoir compris, c'est qu'il est pas possible d'accéder à la ressource container car je ne suis pas dans un control server bindé...
    Je ne vois pas comment accéder à la ressource DataBinder.Eval(Container, "DataItem.id_Fichier") sans utiliser le databinder.eval() ...

    Pouvez m'éclairer ?

  2. #2
    Modérateur

    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2007
    Messages
    1 996
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 996
    Points : 3 102
    Points
    3 102
    Par défaut
    Tu as une erreur de syntaxe dans ton code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <TD align="left" vAlign="top" align="center" width="124px">
    <% if (DataBinder.Eval(Container, "DataItem.id_Fichier").ToString().Substring(0, 2) == "DLG")
    {%>
    <asp:HyperLink id=Hyperlink2 runat="server" width="124px" Text='<%# DataBinder.Eval(Container.DataItem "id_Fichier") %>' Font-Underline="True" CssClass="bleu" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.id_Fichier", "http://jeanlutz.dyndns.org/download/micro/{0}.maj") %>'></asp:HyperLink>
    <% }
    else
    { %>
    <asp:HyperLink id=Hyperlink1 runat="server" width="124px" Text='<%# DataBinder.Eval(Container.DataItem "id_Fichier") %>' Font-Underline="True" CssClass="bleu" NavigateUrl='<%# DataBinder.Eval(Container.DataItem "id_Fichier", "http://jeanlutz.dyndns.org/download/micro/{0}.exe") %>'></asp:HyperLink>
    <% } %>
    </TD>
    il faut écrire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DataBinder.Eval(Container.DataItem, "id")
    et pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DataBinder.Eval(Container, "DataItem.id")

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 74
    Points : 55
    Points
    55
    Par défaut
    Nope c'est la même "Container n'existe pas dans le contexte actuel" ...
    Il semblerai que Container ne soit utilisableque dans un control server bindé.

    Je n'arrive pas à accéder à la ressource autrement ...
    Merci quand même !

  4. #4
    Membre expérimenté Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 47
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Points : 1 352
    Points
    1 352
    Par défaut
    DataBinder.Eval(Container.DataItem, "id") va aller chercher une information ("databind") dansune source de données.

    si tu ne fais pas un binding comment veux tu acceder à une quelconque information?

    Montre nous plus de code pour que l'on comprenne comment tu t'y prends...

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 74
    Points : 55
    Points
    55
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    <%@ Control Language="c#" Inherits="JlsaWeb2005.Web.EspaceClient.LogicielMicroDetails" CodeFile="logicielmicrodetails.ascx.cs" %>
    <asp:DataList id=DataList1 DataSource="<%# dsAffLogicielsMicro1 %>" DataMember="Appareils" runat="server" width="100%" CellPadding="0" ondatabinding="DataList1_DataBinding">
    	<ItemTemplate>
    		<TABLE id="Table1" cellSpacing="0" cellPadding="10" width="100%" border="0">
    			<TR>
    				<TD style="BORDER-RIGHT: #3300cc 1px solid; BORDER-LEFT: #3300cc 1px solid" vAlign="top"
    					width="100">
    					<asp:Label id=Label1 width="100px" runat="server" BorderColor="MediumSlateBlue" BorderWidth="0px" Text='<%# DataBinder.Eval(Container, "DataItem.id_Appareil") + ": " %>' Font-Bold="True">
    					</asp:Label>
    					<asp:Label id=Label2 runat="server" BorderColor="MediumSlateBlue" Text='<%# DataBinder.Eval(Container, "DataItem.Appareil") %>' Font-Size="9pt">
    					</asp:Label></TD>
    				</TD>
    			</tr>
    				<TD vAlign="top">
    					<asp:DataList id=DataList2 CellPadding="0" width="105%" runat="server" DataSource='<%# DataBinder.Eval(Container, "DataItem.Appareils_Fichiers") %>' ShowFooter="False" ShowHeader="False" HorizontalAlign="Left">
    						<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle>
    						<ItemTemplate>
    							<TABLE id="Table14" cellSpacing="0" cellPadding="0" width="100%" border="0">
    								<TR>
    									<TD align="left" vAlign="top" width="70px">
    										<asp:Label id="LblLangue" runat="server" width="70px" Text='<%# DataBinder.Eval(Container, "DataItem.Langue") %>'>
    										</asp:Label></TD>
    									<TD align="left" vAlign="top" align="center" width="124px">
    									    <% if (DataBinder.Eval(Container.DataItem, "id_Fichier").ToString().Substring(0, 2) == "DLG")
                                            {%>
    									    <asp:HyperLink id=Hyperlink2 runat="server" width="124px" Text='<%# DataBinder.Eval(Container, "DataItem.id_Fichier") %>' Font-Underline="True" CssClass="bleu" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.id_Fichier", "http://jeanlutz.dyndns.org/download/micro/{0}.maj") %>'></asp:HyperLink>
    									    <% }
                                            else
                                            { %>
    										<asp:HyperLink id=Hyperlink1 runat="server" width="124px" Text='<%# DataBinder.Eval(Container, "DataItem.id_Fichier") %>' Font-Underline="True" CssClass="bleu" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.id_Fichier", "http://jeanlutz.dyndns.org/download/micro/{0}.exe") %>'></asp:HyperLink>
    										<% } %>
    									</TD>
    									<TD align="left" vAlign="top" width="75px">
    										<asp:Label id=LblDateMAJ runat="server" width="75px" Text='<%# DataBinder.Eval(Container, "DataItem.DateMAJ", "{0:d}") %>'>
    										</asp:Label></TD>
    									<TD align="left" vAlign="top" width="100%">
    										<asp:Label id=LblCommentaire runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Commentaire") %>'>
    										</asp:Label></TD>
    								</TR>
    							</TABLE>
    							&nbsp;
    						</ItemTemplate>
    					</asp:DataList></TD>
    				<TD></TD>
    			</TR>
    		</TABLE>
    	</ItemTemplate>
    </asp:DataList>
    vla tout le code de la dite page.

    Ce morceau de code DataBinder.Eval(Container, "DataItem.id_Fichier") fonctionne dans les balise hyperlink d'asp mais dans un morceaux de code encapsuler par <% %> non...
    Je vous avoue que je suis largement dépassé ... Mais merci de votre aide quand même !

  6. #6
    Membre expérimenté Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 47
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Points : 1 352
    Points
    1 352
    Par défaut
    pourquoi ne pas faire quequechose comme ca alors :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <%# Boolean? valuetrue:valuefalse %>
    ce qui dans ton cas t'amenerait à:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <asp:HyperLink runat="server"
       width="124px" 
       Text='<%# DataBinder.Eval(Container.DataItem "id_Fichier") %>'   
       Font-Underline="True" CssClass="bleu" 
       NavigateUrl='<%# 
       DataBinder.Eval(Container.DataItem, "id_Fichier").ToString().Substring(0, 2) == "DLG" ? DataBinder.Eval(Container, "DataItem.id_Fichier",   
            "http://jeanlutz.dyndns.org/download/micro/{0}.maj") :
     DataBinder.Eval(Container, "DataItem.id_Fichier", "http://jeanlutz.dyndns.org/download/micro/{0}.exe")  %>'>
    </asp:HyperLink>

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 74
    Points : 55
    Points
    55
    Par défaut
    Iop ! Merci au dessus ta solution était la bonne ! Sa fonctionne nicquel !

    Merci et Bye !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème avec une UDF
    Par kanmaber dans le forum Bases de données
    Réponses: 2
    Dernier message: 27/08/2004, 23h42
  2. [JBOSS] [Struts] Problème avec une application
    Par Tiercel dans le forum Wildfly/JBoss
    Réponses: 5
    Dernier message: 13/07/2004, 13h50
  3. Problème avec une instruction OUTER /Postgres
    Par Volcomix dans le forum Langage SQL
    Réponses: 14
    Dernier message: 21/04/2004, 16h56
  4. problème avec une requête imbriquée
    Par jaimepasteevy dans le forum Langage SQL
    Réponses: 13
    Dernier message: 05/12/2003, 10h29
  5. Problème avec une procédure stockée
    Par in dans le forum Langage SQL
    Réponses: 4
    Dernier message: 27/05/2003, 15h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo