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 :

Liaison Data dans fichier aspx


Sujet :

ASP.NET

  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2006
    Messages
    130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Juillet 2006
    Messages : 130
    Par défaut Liaison Data dans fichier aspx
    Bonjour,

    Je viens de passer sur un nouveau projet (sous VS2012 alors que j'étais depuis longtemps sur le 2005) sous lequel mes habitudes sont complètement chamboulées. En effet je suis sous Vb, et plus du coté code-behind (j'avais l'habitude de tout faire dans le .vb et la partie HTML et composants restant que pour le design).

    Je dois donc m'adapter et j'ai l'impression de repartir de zéro... découvrant aussi link to SQL et les composant Telerik me remplaçant mes vieux infragistics.

    Je vais tenter de vous expliquer mon problème :

    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
    49
    50
     
    ...<ContentTemplate>                                             
                                                 <asp:ListView ID="ListView1" runat="server" DataSourceID="LinqDataSource1" GroupItemCount="3">
                                                     <EmptyDataTemplate>
                                                         <table runat="server" style="">
                                                             <tr>
                                                                 <td>Aucune donnée n'a été retournée.</td>
                                                             </tr>
                                                         </table>
                                                     </EmptyDataTemplate>
                                                     <EmptyItemTemplate>
                                                         <td runat="server" />
                                                     </EmptyItemTemplate>
                                                     <GroupTemplate>
                                                         <tr runat="server" id="itemPlaceholderContainer">
                                                             <td runat="server" id="itemPlaceholder"></td>
                                                         </tr>
                                                     </GroupTemplate>
                                                     <ItemTemplate>
                                                         <td runat="server" style="">idRubrique:
                                                             <asp:Label Text='<%# Eval("idRubrique") %>' runat="server" ID="idRubriqueLabel" /><br />
                                                             idGrpRubrique:
                                                             <asp:Label Text='<%# Eval("idGrpRubrique") %>' runat="server" ID="idGrpRubriqueLabel" /><br />
                                                             code:
                                                             <asp:Label Text='<%# Eval("code") %>' runat="server" ID="codeLabel" /><br />
                                                             libelle:
                                                             <%# Me.test  %>                                                         
                                                             <%--<asp:Label Text='<%# Eval("libelle") %>' runat="server" ID="libelleLabel" /><br />--%>
                                                             <telerik:RadTextTile ID="RadTextTile6" runat="server" Text='<%# Eval("libelle")%>'  Height="20" >
                                                             </telerik:RadTextTile>
                                                         </td>
                                                     </ItemTemplate>
                                                     <LayoutTemplate>
                                                         <table runat="server">
                                                             <tr runat="server">
                                                                 <td runat="server">
                                                                     <table runat="server" id="groupPlaceholderContainer" style="" border="0">
                                                                         <tr runat="server" id="groupPlaceholder"></tr>
                                                                     </table>
                                                                 </td>
                                                             </tr>
                                                             <tr runat="server">
                                                                 <td runat="server" style=""></td>
                                                             </tr>
                                                         </table>
                                                     </LayoutTemplate>                                                 
                                                 </asp:ListView>
     
                                                 <asp:LinqDataSource runat="server" EntityTypeName="" ID="LinqDataSource1" ContextTypeName="DataClassesDataContext" OrderBy="iOrdre" Select="new (idRubrique, idGrpRubrique, code, libelle)" TableName="tBG_Rubrique"></asp:LinqDataSource>
                                             </ContentTemplate>...
    J'ai fais ma connexion link to SQL la plus basique (lister le contenu d'une table), j'ai mis un listview qui m'a bien lister le contenu de mes données (via Eval : nouveau pour moi) je pensais pouvoir faire de même que le composant de base "Label" avec un composant Telerik, en l’occurrence un RadTextTile, mais lors de l'affichage, je n'est pas mon libelle et je ne comprends pas pourquoi.

    Si quelqu'un pouvais m'éclaircir... Merci d'avance.

    Vincent.

  2. #2
    Membre émérite
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    777
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2003
    Messages : 777
    Par défaut
    Peux avoir le model de ton linq to sql ?

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2006
    Messages
    130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Juillet 2006
    Messages : 130
    Par défaut
    Citation Envoyé par Dokho1000 Voir le message
    Peux avoir le model de ton linq to sql ?
    Voici, comme j'ai dis, pour le moment, c'est juste une liaison directe de table avec un "order by" c'est tout

    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Data.Linq
    Imports System.Data.Linq.Mapping
    Imports System.Linq
    Imports System.Linq.Expressions
    Imports System.Reflection
     
     
    <Global.System.Data.Linq.Mapping.DatabaseAttribute(Name:="BSiteMap")>  _
    Partial Public Class DataClassesDataContext
    	Inherits System.Data.Linq.DataContext
     
    	Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource = New AttributeMappingSource()
     
      #Region "Définitions de méthodes d'extensibilité"
      Partial Private Sub OnCreated()
      End Sub
      Partial Private Sub InserttBG_Rubrique(instance As tBG_Rubrique)
        End Sub
      Partial Private Sub UpdatetBG_Rubrique(instance As tBG_Rubrique)
        End Sub
      Partial Private Sub DeletetBG_Rubrique(instance As tBG_Rubrique)
        End Sub
      #End Region
     
    	Public Sub New()
    		MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("BSiteMapConnectionString").ConnectionString, mappingSource)
    		OnCreated
    	End Sub
     
    	Public Sub New(ByVal connection As String)
    		MyBase.New(connection, mappingSource)
    		OnCreated
    	End Sub
     
    	Public Sub New(ByVal connection As System.Data.IDbConnection)
    		MyBase.New(connection, mappingSource)
    		OnCreated
    	End Sub
     
    	Public Sub New(ByVal connection As String, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
    		MyBase.New(connection, mappingSource)
    		OnCreated
    	End Sub
     
    	Public Sub New(ByVal connection As System.Data.IDbConnection, ByVal mappingSource As System.Data.Linq.Mapping.MappingSource)
    		MyBase.New(connection, mappingSource)
    		OnCreated
    	End Sub
     
    	Public ReadOnly Property tBG_Rubrique() As System.Data.Linq.Table(Of tBG_Rubrique)
    		Get
    			Return Me.GetTable(Of tBG_Rubrique)
    		End Get
    	End Property
    End Class
     
    <Global.System.Data.Linq.Mapping.TableAttribute(Name:="dbo.tBG_Rubrique")>  _
    Partial Public Class tBG_Rubrique
    	Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
     
    	Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)
     
    	Private _idRubrique As Short
     
    	Private _idGrpRubrique As Byte
     
    	Private _code As String
     
    	Private _libelle As String
     
    	Private _idRubriqueParent As Short
     
    	Private _iOrdre As Byte
     
        #Region "Définitions de méthodes d'extensibilité"
        Partial Private Sub OnLoaded()
        End Sub
        Partial Private Sub OnValidate(action As System.Data.Linq.ChangeAction)
        End Sub
        Partial Private Sub OnCreated()
        End Sub
        Partial Private Sub OnidRubriqueChanging(value As Short)
        End Sub
        Partial Private Sub OnidRubriqueChanged()
        End Sub
        Partial Private Sub OnidGrpRubriqueChanging(value As Byte)
        End Sub
        Partial Private Sub OnidGrpRubriqueChanged()
        End Sub
        Partial Private Sub OncodeChanging(value As String)
        End Sub
        Partial Private Sub OncodeChanged()
        End Sub
        Partial Private Sub OnlibelleChanging(value As String)
        End Sub
        Partial Private Sub OnlibelleChanged()
        End Sub
        Partial Private Sub OnidRubriqueParentChanging(value As Short)
        End Sub
        Partial Private Sub OnidRubriqueParentChanged()
        End Sub
        Partial Private Sub OniOrdreChanging(value As Byte)
        End Sub
        Partial Private Sub OniOrdreChanged()
        End Sub
        #End Region
     
    	Public Sub New()
    		MyBase.New
    		OnCreated
    	End Sub
     
    	<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_idRubrique", AutoSync:=AutoSync.OnInsert, DbType:="SmallInt NOT NULL IDENTITY", IsPrimaryKey:=true, IsDbGenerated:=true)>  _
    	Public Property idRubrique() As Short
    		Get
    			Return Me._idRubrique
    		End Get
    		Set
    			If ((Me._idRubrique = value)  _
    						= false) Then
    				Me.OnidRubriqueChanging(value)
    				Me.SendPropertyChanging
    				Me._idRubrique = value
    				Me.SendPropertyChanged("idRubrique")
    				Me.OnidRubriqueChanged
    			End If
    		End Set
    	End Property
     
    	<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_idGrpRubrique", DbType:="TinyInt NOT NULL")>  _
    	Public Property idGrpRubrique() As Byte
    		Get
    			Return Me._idGrpRubrique
    		End Get
    		Set
    			If ((Me._idGrpRubrique = value)  _
    						= false) Then
    				Me.OnidGrpRubriqueChanging(value)
    				Me.SendPropertyChanging
    				Me._idGrpRubrique = value
    				Me.SendPropertyChanged("idGrpRubrique")
    				Me.OnidGrpRubriqueChanged
    			End If
    		End Set
    	End Property
     
    	<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_code", DbType:="NVarChar(10) NOT NULL", CanBeNull:=false)>  _
    	Public Property code() As String
    		Get
    			Return Me._code
    		End Get
    		Set
    			If (String.Equals(Me._code, value) = false) Then
    				Me.OncodeChanging(value)
    				Me.SendPropertyChanging
    				Me._code = value
    				Me.SendPropertyChanged("code")
    				Me.OncodeChanged
    			End If
    		End Set
    	End Property
     
    	<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_libelle", DbType:="NVarChar(MAX) NOT NULL", CanBeNull:=false)>  _
    	Public Property libelle() As String
    		Get
    			Return Me._libelle
    		End Get
    		Set
    			If (String.Equals(Me._libelle, value) = false) Then
    				Me.OnlibelleChanging(value)
    				Me.SendPropertyChanging
    				Me._libelle = value
    				Me.SendPropertyChanged("libelle")
    				Me.OnlibelleChanged
    			End If
    		End Set
    	End Property
     
    	<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_idRubriqueParent", DbType:="SmallInt NOT NULL")>  _
    	Public Property idRubriqueParent() As Short
    		Get
    			Return Me._idRubriqueParent
    		End Get
    		Set
    			If ((Me._idRubriqueParent = value)  _
    						= false) Then
    				Me.OnidRubriqueParentChanging(value)
    				Me.SendPropertyChanging
    				Me._idRubriqueParent = value
    				Me.SendPropertyChanged("idRubriqueParent")
    				Me.OnidRubriqueParentChanged
    			End If
    		End Set
    	End Property
     
    	<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_iOrdre", DbType:="TinyInt NOT NULL")>  _
    	Public Property iOrdre() As Byte
    		Get
    			Return Me._iOrdre
    		End Get
    		Set
    			If ((Me._iOrdre = value)  _
    						= false) Then
    				Me.OniOrdreChanging(value)
    				Me.SendPropertyChanging
    				Me._iOrdre = value
    				Me.SendPropertyChanged("iOrdre")
    				Me.OniOrdreChanged
    			End If
    		End Set
    	End Property
     
    	Public Event PropertyChanging As PropertyChangingEventHandler Implements System.ComponentModel.INotifyPropertyChanging.PropertyChanging
     
    	Public Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
     
    	Protected Overridable Sub SendPropertyChanging()
    		If ((Me.PropertyChangingEvent Is Nothing)  _
    					= false) Then
    			RaiseEvent PropertyChanging(Me, emptyChangingEventArgs)
    		End If
    	End Sub
     
    	Protected Overridable Sub SendPropertyChanged(ByVal propertyName As [String])
    		If ((Me.PropertyChangedEvent Is Nothing)  _
    					= false) Then
    			RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    		End If
    	End Sub
    End Class

  4. #4
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2006
    Messages
    130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Juillet 2006
    Messages : 130
    Par défaut
    Un collègue vient de trouver, mais tout les deux nous ne savons que ça marche, mais sans comprendre pourquoi on doit mettre ceci et aussi à quoi ça correspond.
    Si l'on peut nous éclairer, merci.

    Solution :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <telerik:RadTextTile ID="RadTextTile6" runat="server"  Text='<%# DataBinder.Eval(Container.DataItem, "libelle")%>'  Height="20" >
    </telerik:RadTextTile>

  5. #5
    Membre émérite
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    777
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2003
    Messages : 777
    Par défaut
    Citation Envoyé par conan76 Voir le message
    Un collègue vient de trouver, mais tout les deux nous ne savons que ça marche, mais sans comprendre pourquoi on doit mettre ceci et aussi à quoi ça correspond.
    Si l'on peut nous éclairer, merci.

    Solution :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <telerik:RadTextTile ID="RadTextTile6" runat="server"  Text='<%# DataBinder.Eval(Container.DataItem, "libelle")%>'  Height="20" >
    </telerik:RadTextTile>
    Effectivement c'est la bonne fàcon de faire, j'avais pas réalisé dans ton code que tu avais omis le container et le databinder.

    Idéalement ne pas utiliser le DataBinder.Eval afin d’éviter des pertes de performances (eval utilise la reflection) et plutot caster le dataitem dans le type de l'objet attendu (ex :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     (Container.DataItem as tBG_Rubrique).libelle
    ) de plus ca évitera de faire des fautes dans l'intitulé de la propriété puisque ce sera compilé

    A+

Discussions similaires

  1. Save Data sur Data dans Fichier text
    Par jokenjo dans le forum MATLAB
    Réponses: 4
    Dernier message: 29/10/2009, 14h03
  2. Réponses: 2
    Dernier message: 26/10/2008, 19h02
  3. Réponses: 6
    Dernier message: 07/02/2008, 10h35
  4. Réponses: 10
    Dernier message: 08/02/2007, 13h18
  5. [HTML] Inclure un fichier .aspx dans une page HTML
    Par Miles Raymond dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 04/05/2006, 12h07

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