En primer lugar, creo un control de usuario, y lo llamo calendariomuestra.ascx.
Creo dos botones para ir al mes anterior y al siguiente y dos DropDownList para seleccionar el mes y el año:
<asp:Button ID="prev" runat="server" onclick="prev_Click" Text="<" />
<asp:Button ID="next" runat="server" onclick="next_Click" Text=">" />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="1">Enero</asp:ListItem>
<asp:ListItem Value="2">Febrero</asp:ListItem>
<asp:ListItem Value="3">Marzo</asp:ListItem>
<asp:ListItem Value="4">Abril</asp:ListItem>
<asp:ListItem Value="5">Mayo</asp:ListItem>
<asp:ListItem Value="6">Junio</asp:ListItem>
<asp:ListItem Value="7">Julio</asp:ListItem>
<asp:ListItem Value="8">Agosto</asp:ListItem>
<asp:ListItem Value="9">Septiembre</asp:ListItem>
<asp:ListItem Value="10">Octubre</asp:ListItem>
<asp:ListItem Value="11">Noviembre</asp:ListItem>
<asp:ListItem Value="12">Diciembre</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>2006</asp:ListItem>
<asp:ListItem>2007</asp:ListItem>
<asp:ListItem>2008</asp:ListItem>
<asp:ListItem>2009</asp:ListItem>
<asp:ListItem>2010</asp:ListItem>
<asp:ListItem>2011</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
Y en el fichero de código defino las propiedades:
public DateTime fini = Convert.ToDateTime("1/7/2008");
public DateTime ffin = Convert.ToDateTime("31/7/2008");
// Contendrán las fechas de inicio y fin del mes seleccionado
private int _mes;
private int _ano = System.DateTime.Today.Year;
private string _ancho; // anchura de las columnas del calendario.
private string _url = "nada"; // url de la página a la que enlaza cada fecha.
private DataTable _datosglobal=new DataTable(); //Datos con las fechas
public int Mes
{
get
{
return _mes;
}
set
{
_mes = value;
if (_ano > 0)
{
fini = Convert.ToDateTime("1/" + _mes.ToString() + "/" + _ano.ToString());
ffin = Convert.ToDateTime(System.DateTime.DaysInMonth(_ano, _mes).ToString() +
"/" + _mes.ToString() + "/" + _ano.ToString());
}
}
}
public int Ano
{
get
{
return _ano;
}
set
{
_ano = value;
if (_mes > 0)
{
fini = Convert.ToDateTime("1/" + _mes.ToString() + "/" + _ano.ToString());
ffin = Convert.ToDateTime(System.DateTime.DaysInMonth(_ano, _mes).ToString()
+ "/" + _mes.ToString() + "/" + _ano.ToString());
}
}
}
public string ancho
{
get
{
return _ancho;
}
set
{
_ancho = value;
}
}
public string url
{
get
{
return _url;
}
set
{
_url = value;
}
}
public DataTable datosglobal
{
get
{
return _datosglobal;
}
set
{
_datosglobal = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Mes = Convert.ToInt16(System.DateTime.Today.Month);
Ano = Convert.ToInt16(System.DateTime.Today.Year);
this.DropDownList1.SelectedValue = Mes.ToString();
this.DropDownList2.SelectedValue = Ano.ToString();
}
}
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario