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 :

[Asp.Net] Question création calendrier


Sujet :

ASP.NET

  1. #1
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut [Asp.Net] Question création calendrier
    Bonjour tout le monde,

    Je souhaiterais savoir si vous avez déjà du créer un calendrier qui représente une année complète et qui s'affiche en une page.
    Exemple: la première ligne indique les mois de l'année
    La deuxième indique le jour de la semaine et puis pour chaque mois le numéro de jour du mois
    Exemple

    Le 1er mai 2015 tombe un vendredi (ha ben oui c'est aujourd'hui)
    Je vais donc avoir à la 5ème ligne de mon tableau (qui représente le jour: Vendredi) le numéro 1 dans la colonne du mois de mai
    A la 6ème ligne je vais avoir le numéro 2
    etc

    Une idée sur : comment le réaliser ?

    Voici un exemple de ce que je voudrais faire : Nom : PrtScr capture.jpg
Affichages : 322
Taille : 94,8 Ko

  2. #2
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2003
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 274
    Points : 372
    Points
    372
    Par défaut
    Pour ceux que cela intéresse voici la solution que j'ai développé:

    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
    <asp:GridView ID="gridviewCalendar" runat="server" AutoGenerateColumns="false" GridLines="Both"
                BorderWidth="1" BorderStyle="Solid"
                CellPadding="1" CellSpacing="2">
                <Columns>
                    <asp:BoundField DataField="DayText" HeaderText="Days" />
                    <asp:BoundField DataField="DayJanuary.Value" HeaderText="January" />
                    <asp:BoundField DataField="DayFebruary.Value" HeaderText="February" />
                    <asp:BoundField DataField="DayMarch.Value" HeaderText="March" />
                    <asp:BoundField DataField="DayApril.Value" HeaderText="April" />
                    <asp:BoundField DataField="DayMay.Value" HeaderText="May" />
                    <asp:BoundField DataField="DayJune.Value" HeaderText="June" />
                    <asp:BoundField DataField="DayJuly.Value" HeaderText="July" />
                    <asp:BoundField DataField="DayAugust.Value" HeaderText="August" />
                    <asp:BoundField DataField="DaySeptember.Value" HeaderText="September" />
                    <asp:BoundField DataField="DayOctober.Value" HeaderText="October" />
                    <asp:BoundField DataField="DayNovember.Value" HeaderText="November" />
                    <asp:BoundField DataField="DayDecember.Value" HeaderText="December" />
     
                </Columns>
     
            </asp:GridView>
    CS:

    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
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
     
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<string> days = new List<string>() { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
     
            List<CalendarDefinition> list = new List<CalendarDefinition>();
            int cpt = 0;
            int january = 1;
            int february = 1;
            int march = 1;
            int april = 1;
            int may = 1;
            int june = 1;
            int july = 1;
            int august = 1;
            int september = 1;
            int october = 1;
            int november = 1;
            int december = 1;
     
            for (int i = 0; i <= 41; i++) // Lundi à Dimanche sur 5 semaines
            {
                cpt = (int)(i / 7);
                string dayName = days[i - (7 * cpt)];
     
                CalendarDefinition item = new CalendarDefinition();
                item.DayText = dayName;
     
                item.DayJanuary = GetDefinition(1, ref january, dayName) as DayMonthDefinition;
                item.DayFebruary = GetDefinition(2, ref february, dayName) as DayMonthDefinition;
                item.DayMarch = GetDefinition(3, ref march, dayName) as DayMonthDefinition;
                item.DayApril = GetDefinition(4, ref april, dayName) as DayMonthDefinition;
                item.DayMay = GetDefinition(5, ref may, dayName) as DayMonthDefinition;
                item.DayJune = GetDefinition(6, ref june, dayName) as DayMonthDefinition;
                item.DayJuly = GetDefinition(7, ref july, dayName) as DayMonthDefinition;
                item.DayAugust = GetDefinition(8, ref august, dayName) as DayMonthDefinition;
                item.DaySeptember = GetDefinition(9, ref september, dayName) as DayMonthDefinition;
                item.DayOctober = GetDefinition(10, ref october, dayName) as DayMonthDefinition;
                item.DayNovember = GetDefinition(11, ref november, dayName) as DayMonthDefinition;
                item.DayDecember = GetDefinition(12, ref december, dayName) as DayMonthDefinition;
     
                january++;
                february++;
                march++;
                april++;
                may++;
                june++;
                july++;
                august++;
                september++;
                october++;
                november++;
                december++;
     
                list.Add(item);
            }
     
            gridviewCalendar.DataSource = list;
            gridviewCalendar.DataBind();
        }
     
        private object GetDefinition(int month, ref int day, string dayName)
        {
            DateTime temp;
            bool succeed = DateTime.TryParse(string.Format("{0}-{1}-{2}", 2015, month, day), out temp);
            if (succeed && temp.DayOfWeek.ToString().ToLower() == dayName.ToLower())
            {
                return new DayMonthDefinition()
                    {
                        DayNumber = day,
                        Value = day.ToString()
                    };
            }
            else
            {
                day--;
                return null;
            }
        }
    }
     
    public class CalendarDefinition
    {
        public string DayText { get; set; }
        public DayMonthDefinition DayJanuary { get; set; }
        public DayMonthDefinition DayFebruary { get; set; }
        public DayMonthDefinition DayMarch { get; set; }
        public DayMonthDefinition DayApril { get; set; }
        public DayMonthDefinition DayMay { get; set; }
        public DayMonthDefinition DayJune { get; set; }
        public DayMonthDefinition DayJuly { get; set; }
        public DayMonthDefinition DayAugust { get; set; }
        public DayMonthDefinition DaySeptember { get; set; }
        public DayMonthDefinition DayOctober { get; set; }
        public DayMonthDefinition DayNovember { get; set; }
        public DayMonthDefinition DayDecember { get; set; }
    }
     
    public class DayMonthDefinition
    {
        public int DayNumber { get; set; }
        public string Value { get; set; }
    }

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 19/07/2010, 11h24
  2. Réponses: 1
    Dernier message: 14/01/2010, 13h52
  3. [ASP.NET MVC] Création des règles de validation
    Par Leelith dans le forum ASP.NET
    Réponses: 8
    Dernier message: 29/09/2009, 18h49
  4. Réponses: 10
    Dernier message: 03/11/2008, 16h15
  5. [ASP.NET] question sur DataView.RowFilter
    Par spiksou dans le forum ASP.NET
    Réponses: 3
    Dernier message: 20/04/2007, 13h24

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