<asp:DataList id="dlCalandar"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
ShowBorder="True"
ShowFooter="True"
runat="server"
width="50%"
>
<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>
<ItemStyle BackColor="Silver">
</ItemStyle>
<AlternatingItemStyle
BackColor="DarkGray">
</AlternatingItemStyle>
<HeaderTemplate>
<h4>My Calender</h4>
</HeaderTemplate>
<ItemTemplate>
Date: <%# DataBinder.Eval(Container.DataItem,
"Date") %>
<br>
Days: <%# DataBinder.Eval(Container.DataItem,
"Days") %>
</ItemTemplate>
<AlternatingItemTemplate>
Date: <%# DataBinder.Eval(Container.DataItem,
"Date") %>
<br>
Days: <%# DataBinder.Eval(Container.DataItem,
"Days") %>
</AlternatingItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSunday"
runat="server">*
Holidays</asp:Label>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right"
/>
</asp:DataList>
.aspx.cs page
protected void BindCalandar()
{
DataTable dt = myCal().ToTable();
if (dt.Rows.Count > 0)
{
int repColumns = 0;
if (dt.Rows.Count % 6 == 0)
{
repColumns =
dt.Rows.Count / 6;
}
else
{
repColumns =
(dt.Rows.Count / 6) + 1;
}
dlCalandar.RepeatColumns
= repColumns;
}
dlCalandar.DataSource =
dt;
dlCalandar.DataBind();
}
protected DataView myCal()
{
DataTable dt = new DataTable();
DataRow dr;
// Here is the columns of the table.
dt.Columns.Add(new DataColumn("Date", typeof(Int32)));
dt.Columns.Add(new DataColumn("Days", typeof(String)));
int Year = DateTime.UtcNow.Year;
int Month = DateTime.UtcNow.Month;
int Days = DateTime.DaysInMonth(Year,
Month);
for (int i = 1; i < Days + 1;
i++)
{
var
thisYear = new DateTime(Year,
Month, i);
var dayOfWeek = thisYear.DayOfWeek;
dr = dt.NewRow();
dr[0] = i;
if (dayOfWeek == DayOfWeek.Saturday
|| dayOfWeek == DayOfWeek.Sunday)
{
dr[1] = "*" +
dayOfWeek.ToString() + "";
}
else
{
dr[1] =
dayOfWeek.ToString();
}
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
Call it on Page Load Event:
protected void Page_Load(object
sender, EventArgs e)
{
if (!IsPostBack)
{
BindCalandar();
}
Comments