Jump to content
amvm

Colocar o calendário do ASP a mostrar semana a semana

Recommended Posts

amvm

Boa noite

Estou com dificuldades em alterar o calendário do ASP de modo a que apresentas apenas a semana currente.

Encontrei um código na net que me mostra a semana currente como pretendo, mas não estou a conseguir alterar de modo a que, quando clico nas setas (previous/next) ele me avance para a semana anterior/próxima.

Alguém me consegue ajudar?

Desde já obrigado.

Eis o código:

protected void Page_Load(object sender, System.EventArgs e)

{

DateTime dtime = default(DateTime);

dtime = DateTime.Now;

Calendar1.VisibleDate = dtime;

}

public static int toWeek(System.DateTime tdDate)

{

System.Globalization.CultureInfo CultureI= new System.Globalization.CultureInfo("en-US");

System.Globalization.Calendar myCal = CultureI.Calendar;

System.Globalization.CalendarWeekRule myCWR = CultureI.DateTimeFormat.CalendarWeekRule;

DayOfWeek myFirstDOW = CultureI.DateTimeFormat.FirstDayOfWeek;

return myCal.GetWeekOfYear(tdDate, myCWR, myFirstDOW);

}

protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)

{

if (toWeek(e.Day.Date) != toWeek(Calendar1.SelectedDate))

{

e.Cell.Text = "";

}

}

Share this post


Link to post
Share on other sites
Ruka284

ve se este codigo dá-te jeito

asp:UpdatePanel runat="server" ID="updatePanel1"><ContentTemplate>

<obout:Calendar ID="Calendar1"

runat="server"

Columns="1"

AutoPostBack="true"

TitleText="Week select"

OnDateChanged="Date_Changed"

StyleFolder="styles/default">

</obout:Calendar>

</ContentTemplate></asp:UpdatePanel>

ou este

protected void Date_Changed (o objeto, EventArgs e)

{

DateTime SelectedDate = Calendar1.SelectedDate;

if (DateTime.Compare (SelectedDate, new DateTime (0)) == 0)

{

voltar;

}

Calendar1.SpecialDates.Clear ();

for (int index = 0; index <7; índice + +)

{

int addedDays = (int) (index - selectedDate.DayOfWeek);

Calendar1.AddSpecialDate (selectedDate.AddDays (addedDays). Year,

selectedDate.AddDays (addedDays). mês,

. selectedDate.AddDays (addedDays) Dia, a "Semana select");

}

}

Edited by Ruka284

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.