<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlMonth" runat="server" OnSelectedIndexChanged="ddlMonth_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="Jan" Value="1"></asp:ListItem>
<asp:ListItem Text="Feb" Value="2"></asp:ListItem>
<asp:ListItem Text="Mar" Value="3"></asp:ListItem>
<asp:ListItem Text="Apr" Value="4"></asp:ListItem>
<asp:ListItem Text="May" Value="5"></asp:ListItem>
<asp:ListItem Text="Jun" Value="6"></asp:ListItem>
<asp:ListItem Text="Jul" Value="7"></asp:ListItem>
<asp:ListItem Text="Aug" Value="7"></asp:ListItem>
<asp:ListItem Text="Sep" Value="9"></asp:ListItem>
<asp:ListItem Text="Oct" Value="10"></asp:ListItem>
<asp:ListItem Text="Nov" Value="11"></asp:ListItem>
<asp:ListItem Text="Dec" Value="12"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlYear" runat="server" OnSelectedIndexChanged="ddlYear_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<asp:Repeater ID="rptCale" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>S</td>
<td>M</td>
<td>T</td>
<td>W</td>
<td>T</td>
<td>F</td>
<td>S</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("1") %>
</td>
<td>
<%# Eval("2") %>
</td>
<td>
<%# Eval("3") %>
</td>
<td>
<%# Eval("4") %>
</td>
<td>
<%# Eval("5") %>
</td>
<td>
<%# Eval("6") %>
</td>
<td>
<%# Eval("7") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
---------------------------------------------------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropDown();
}
}
protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
BindCale(Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlYear.SelectedValue));
}
protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
BindCale(Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlYear.SelectedValue));
}
private void BindDropDown()
{
var Date = Enumerable.Range(1990, 2099).Select(i => i.ToString());
ddlYear.DataSource = Date;
ddlYear.DataBind();
ddlMonth.SelectedValue = DateTime.Now.Month.ToString();
ddlYear.SelectedValue = DateTime.Now.Year.ToString();
BindCale(Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlYear.SelectedValue));
}
private void BindCale(int Month, int Year)
{
DataTable dt = new DataTable();
dt.Columns.Add("1");
dt.Columns.Add("2");
dt.Columns.Add("3");
dt.Columns.Add("4");
dt.Columns.Add("5");
dt.Columns.Add("6");
dt.Columns.Add("7");
//int Monht = 2;
//int Year = 2012;
DateTime date = new DateTime(Year, Month, 1);
int Fday = Convert.ToInt32(date.DayOfWeek);
int lDay = DateTime.DaysInMonth(Year, Month);
int Inc = 1;
while (Inc < lDay)
{
DataRow dr = dt.NewRow();
for (int i = Fday; i < 7; i++)
{
if (Inc <= lDay)
{
dr[i] = Inc;
}
Inc++;
}
Fday = 0;
dt.Rows.Add(dr);
}
rptCale.DataSource = dt;
rptCale.DataBind();
}
<div>
<asp:DropDownList ID="ddlMonth" runat="server" OnSelectedIndexChanged="ddlMonth_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="Jan" Value="1"></asp:ListItem>
<asp:ListItem Text="Feb" Value="2"></asp:ListItem>
<asp:ListItem Text="Mar" Value="3"></asp:ListItem>
<asp:ListItem Text="Apr" Value="4"></asp:ListItem>
<asp:ListItem Text="May" Value="5"></asp:ListItem>
<asp:ListItem Text="Jun" Value="6"></asp:ListItem>
<asp:ListItem Text="Jul" Value="7"></asp:ListItem>
<asp:ListItem Text="Aug" Value="7"></asp:ListItem>
<asp:ListItem Text="Sep" Value="9"></asp:ListItem>
<asp:ListItem Text="Oct" Value="10"></asp:ListItem>
<asp:ListItem Text="Nov" Value="11"></asp:ListItem>
<asp:ListItem Text="Dec" Value="12"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlYear" runat="server" OnSelectedIndexChanged="ddlYear_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<asp:Repeater ID="rptCale" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>S</td>
<td>M</td>
<td>T</td>
<td>W</td>
<td>T</td>
<td>F</td>
<td>S</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("1") %>
</td>
<td>
<%# Eval("2") %>
</td>
<td>
<%# Eval("3") %>
</td>
<td>
<%# Eval("4") %>
</td>
<td>
<%# Eval("5") %>
</td>
<td>
<%# Eval("6") %>
</td>
<td>
<%# Eval("7") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
---------------------------------------------------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropDown();
}
}
protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
BindCale(Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlYear.SelectedValue));
}
protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
BindCale(Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlYear.SelectedValue));
}
private void BindDropDown()
{
var Date = Enumerable.Range(1990, 2099).Select(i => i.ToString());
ddlYear.DataSource = Date;
ddlYear.DataBind();
ddlMonth.SelectedValue = DateTime.Now.Month.ToString();
ddlYear.SelectedValue = DateTime.Now.Year.ToString();
BindCale(Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlYear.SelectedValue));
}
private void BindCale(int Month, int Year)
{
DataTable dt = new DataTable();
dt.Columns.Add("1");
dt.Columns.Add("2");
dt.Columns.Add("3");
dt.Columns.Add("4");
dt.Columns.Add("5");
dt.Columns.Add("6");
dt.Columns.Add("7");
//int Monht = 2;
//int Year = 2012;
DateTime date = new DateTime(Year, Month, 1);
int Fday = Convert.ToInt32(date.DayOfWeek);
int lDay = DateTime.DaysInMonth(Year, Month);
int Inc = 1;
while (Inc < lDay)
{
DataRow dr = dt.NewRow();
for (int i = Fday; i < 7; i++)
{
if (Inc <= lDay)
{
dr[i] = Inc;
}
Inc++;
}
Fday = 0;
dt.Rows.Add(dr);
}
rptCale.DataSource = dt;
rptCale.DataBind();
}
Comments
Post a Comment