2013-02-22 9 views
6

qualcuno ha idea di come sia possibile passare un elenco di date nel codice sottostante a un calendario, in modo da evidenziare le date presenti nell'elenco. thank youpassare un elenco di date a un calendario JQuery

<script> 
     $(function() { 
     $("#datepicker").datepicker(); 
     }); 
    </script> 

    <p>Date: <input type="text" id="datepicker" /></p> 

elenco di date memorizzati nel codice dietro:

DateTime start = new DateTime(2013, 02, 20); 
     DateTime end = new DateTime(2013, 01, 11); 

     var dates = new List<DateTime>(); 

     for (var dt = start; dt <= end; dt = dt.AddDays(1)) 
     { 
      dates.Add(dt); 
     } 
+0

Sembra come vostro usando una parola chiave riservata come nome di variabile. Spero che userete anche una query ajax per ottenere quella lista di date. Anche questo potrebbe aiutare. http://stackoverflow.com/questions/2385332/jquery-datepicker-highlight-dates – Musk

+0

Fare riferimento qui: [Come il jquery Datepicker ha impostato una data per evidenziare] (http://stackoverflow.com/questions/7523653/how-the-jquery-datepicker-set-some-date-to-highlight) oppure [date highlight jquery datepicker] (http://stackoverflow.com/questions/2385332/jquery-datepicker-highlight-dates) – Charlie

risposta

1

La soluzione più semplice per voi sarebbe quella di creare gestore di asp.net o una pagina web che restituisce le date come oggetti json e le usa su una funzione beforeShowDate all'interno del datepicker:

Ecco la semplice implementazione:

var dates = []; //replace [] with ajax call to the page that returns the dates 
$("#datepicker").datepicker({ 
     dateFormat: "dd-mm-yyyy", 

     beforeShowDay: function (date) { 
      var available = $.inArray(date, dates) > -1; 

      if (available) { 
       return [1]; //return available date 
      } 
      else { 
       return [0]; //return not available 
      } 
     } 
}); 

codice dietro sarebbe simile a questa. Si deve aggiungere System.Web.Extensions.dll come riferimento per essere in grado di utilizzare JavaScriptSerializer

protected void Page_Load(object sender, EventArgs e) 
    { 
     DateTime start = new DateTime(2013, 02, 20); 
     DateTime end = new DateTime(2014, 01, 11); 

     var dates = new List<string>(); 

     for (var dt = start; dt <= end; dt = dt.AddDays(1)) 
     { 
      dates.Add(dt.ToString("dd-MM-yyyy")); 
     } 

     Response.ContentType = "text/javascript"; 
     string json = new JavaScriptSerializer().Serialize(dates); 
     Response.Write(json); 
     Response.End(); 
    }` 
+0

Hey DZL, grazie per aver trovato il tempo di rispondere, ha dato un'occhiata al codice e sembra essere buono ... ma ero a corto di tempo con questo, quindi ho finito con un calendario di asp.net con un tutorial (di cui non sapevo al momento) che consente di evidenziare le date selezionate ... http: //www.codeproject.com/Articles/7929/Highlighting-Important-Dates-in-Calendar Grazie ancora per la risposta, anche se – John

+0

Nessun problema, sono contento di aver potuto aiutare .. –

Problemi correlati