Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii

I m making a calendar in asp.i have two tables date(1 column) and day (1 column). now what i waht to do that fill datalist with these two tables so that header text will be days (sun, mon ...) and items are date from 1 to 31. just tell me how can i bind these fields and dont b panic to set synchronization b/w them.

C#
<asp:DataList ID="DataList1" runat="server" RepeatColumns="7"                     
                    RepeatDirection="Horizontal"  >
                   
                    <HeaderStyle />
                    <HeaderTemplate>
                        <asp:Label ID="Label7" runat="server" Text='<%# Eval("day") %>'>
                    </HeaderTemplate>
                    
                    <itemstyle />
                    
                    <itemtemplate>
                        <asp:Label ID="Label6" runat="server" Text='<%# Eval("id") %>'>
                    </itemtemplate>



and on the code behind
C#
da = new SqlDataAdapter("select date.id, day.day from date,day",con);
            con.Open();
            da.Fill(ds);
            DataList1.DataSource = ds;
            DataList1.DataBind();
            con.Close();


I got 31 *7 times dates in datalist.
Posted
Updated 16-Sep-11 4:44am
v2
Comments
Herman<T>.Instance 16-Sep-11 10:26am    
what have you tried?

1 solution

Hi,

If you really want to generate calender by C# .I use this code for generating calender.

Try this it can helps you

Place this div tag in your webpage like.. default.aspx
ASP.NET
<div id="mycalender" runat="server"></div>


copy this code into your code behind file like...default.aspx.cs

C#
if (!IsPostBack)
  {

      StringBuilder sb = new StringBuilder();
      sb.Append("<table width="40%">");
      sb.Append("<tr><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td><td>Sun</td></tr>");
      for (int i = 1; i <= 35; i++)
      {
          if (i == 1 || i == 8 || i == 15 || i == 22 || i == 29)
          {
              sb.Append("<tr><td>"+i.ToString ()+"</td>");
          }
          else
          {
              if (i <= 31)
              {
                  sb.Append("<td>" + i.ToString() + "</td>");
              }
              else
              {
                  sb.Append("<td></td>");
              }
              if (i == 7 || i == 14 || i == 21 || i == 28)
              {
                  sb.Append("</tr>");
              }
          }
      }
      sb.Append("</table>");

      mycalender.InnerHtml = sb.ToString();
  }


I hope you'll get calender in your page
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900