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 :

[C#] DataSet et Repeater


Sujet :

ASP.NET

  1. #1
    Membre régulier Avatar de NeoMan
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2002
    Messages : 171
    Points : 76
    Points
    76
    Par défaut [C#] DataSet et Repeater
    Bonjour à tous !

    J'aimerais utiliser un DataSet (ayant plusieurs tables) comme DataSource d'un repeater. Je simplifie, a vrai dire j'utilise un ObjectDataSource qui retourne un DataSet.
    J'arrive très bien à accéder à mes données contenues dans la première table, mais comment faire pour changer de table courante ?

    Mon code ASPX :
    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
     
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Select" TypeName="DataBinding"></asp:ObjectDataSource>    
            &nbsp;&nbsp;
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
                <HeaderTemplate>
                    <table border="1">
                        <tr>
                            <td>ids</td>
                            <td>Campagne</td>
                            <td>Culture</td>
                            <td>Variété</td>
                            <td>Code</td>
                            <td>Nom</td>
                            <td>Surface</td>
                            <td>Précédent</td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%# DataBinder.Eval(Container.DataItem, "ids") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Campagne") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Culture") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Variété") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Code")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Nom")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Surface")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Précédent")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>
    Mon code C# :
    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
     
    public class DataBinding
    {
        private DataSet _ds = null;
        public DataSet DS
        {
            get
            {
                try
                {
                    if (_ds == null)
                    {
                        SqlCommand command = new SqlCommand("ProcedureName", new SqlConnection("ConnectionString"));
                        command.CommandType = CommandType.StoredProcedure;
                        SqlDataAdapter adapter = new SqlDataAdapter(command);
                        _ds = new DataSet();
                        command.Connection.Open();
                        adapter.Fill(_ds);
                        command.Connection.Close();
                    }
                }
                catch (Exception e)
                {
                    _ds = null;
                }
                return _ds;
            }
        }
     
        public DataSet Select()
        {
            return DS;
        }
    }
    PS: ceci est un code test... Je sais que c'est un strange d'avoir fait le chargement des données lors du premier l'appel de la propriété...

    Edit:
    Ce que j'aimerais avoir c'est quelque chose du genre :
    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
     
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Select" TypeName="DataBinding"></asp:ObjectDataSource>    
            &nbsp;&nbsp;
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
                <HeaderTemplate>
                    <table border="1">
                        <tr>
                            <td>ids</td>
                            <td>Campagne</td>
                            <td>Culture</td>
                            <td>Variété</td>
                            <td>Code</td>
                            <td>Nom</td>
                            <td>Surface</td>
                            <td>Précédent</td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%# DataBinder.Eval(Container.DataItem, "ids") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Campagne") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Culture") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Variété") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Code")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Nom")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Surface")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Précédent")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>    
     
            <asp:Repeater ID="Repeater2" runat="server" DataSourceID="ObjectDataSource1">
                <HeaderTemplate>
                    <table border="1">
                        <tr>
                            <td>Date</td>
                            <td>Surface</td>
                            <td>Opération</td>
                            <td>Commentaire</td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%# DataBinder.Eval(Container.DataItem, "Date")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Surface")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Opération")%></td>
                        <td><%# DataBinder.Eval(Container.DataItem, "Commentaire")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>
    Que le Repeater2 puisse être associé à la deuxième table.

    @++

    NeoMan
    Vas-y court petit bug! Profites! On verra bien qui rira le dernier...

  2. #2
    Membre confirmé
    Avatar de malbaladejo
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2002
    Messages : 379
    Points : 527
    Points
    527
    Par défaut
    Dans ton dataset tu as 2 datatables.
    Au lieu de passer le dataset comme source de donnée du repeater tu pourrais lui passer un des datatables du dataset.

  3. #3
    Membre régulier Avatar de NeoMan
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2002
    Messages : 171
    Points : 76
    Points
    76
    Par défaut
    Je ne savais pas que l'on pouvait associé un DataTable à un Repeater...
    Donc ça roule!
    Merci !!

    @++

    NeoMan
    Vas-y court petit bug! Profites! On verra bien qui rira le dernier...

  4. #4
    Membre confirmé
    Avatar de malbaladejo
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2002
    Messages : 379
    Points : 527
    Points
    527
    Par défaut
    Tu peux associer tout sorte de conteneur à un Repeater (ArrayList, DataSet, DataTable, Hashtable,...)

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

Discussions similaires

  1. Le dataset.bof ne répond plus.
    Par fplanglois dans le forum Bases de données
    Réponses: 6
    Dernier message: 23/03/2004, 09h45
  2. Modifier l'ordre des Fields d'un dataset
    Par teska dans le forum Bases de données
    Réponses: 3
    Dernier message: 22/03/2004, 16h38
  3. [C#] [SQLSERVER2000] Dataset et Xml
    Par farfadet dans le forum ASP.NET
    Réponses: 11
    Dernier message: 16/03/2004, 16h02
  4. [VB.net][PostgreSQL & ODBC] DataSet => NO_DAT
    Par rebolon dans le forum Accès aux données
    Réponses: 2
    Dernier message: 28/01/2004, 09h01
  5. [FLASH MX 2004 pro] DATASET, XML, ASP
    Par kenshi dans le forum Flash
    Réponses: 4
    Dernier message: 27/01/2004, 10h38

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