:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  
 

Resources

Finding Correct Content Managemet System
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Workflow Managemet Systems
Workflow management is a crucial component in organizing a variety of business processes so that they benefit the business as a whole and increase profitability...

Using the Power of Content Management Systems
With page editors that resemble a word processor program, adding content with a CMS interface is simple and fun. Most CMS software also allows you to change the location of your content pages and links easily, while the back end processes takes care of updating the links throughout your site...

Content Management Systems (CMS): What They Are And Why We Love Them
In the past, individuals who took interest in having and operating their own websites were burdened with the task of learning HTML, DHTML, and other web-based technologies such as JavaScript and CSS. The only alternative to this was, unfortunately, to pocket the expenses and costs required to pay a web developer to build and maintain it for them...

Outsourcing
Post your project for outsourcing and get bids from qualified programmers, designers, interpreters, copywriters.


 

Code Walkthroughs

Datagrid Formatting the Data
We are able to format the content of the datagrid cell by one of two simple methods, dependant upon whether the column is a bound column or whether it is a template column. In our example we shall format the column to have to digits after the decimal point , followed by a...

Datagrid Highlight a Row With Click Through
It is relatively easy to add alternating colours to the rows in your datagrid. However, when we move the mouse over the rows we may want to highlight this row, and possibly to add the option of a click through based on the row selected...

Add a Delete Button to a Datagrid
To add a delete button to a datagrid follows a similar process to adding an edit button. In the datagrid header...

Add an Edit Button to a Datagrid
The datagrid has a predefined editColumn for handling the editing of a datagrid. Adding this simple column definition to a datagrid adds a powerful feature. When a row is not in edit mode the column item shows the word...

Making a Datagrid Row Editable
Two of the most popular methods of editing a datagrid in asp.net are to either select the row and take the user off to a different presentation of the data, or to change the formatting of the row presented in the database with appropriate edit text boxes, checkboxes and...

Adding Tooltips to Datagrid Rows
Adding tooltips to datagrid rows is easy, assuming that you have already created the code for adding row highlighting. In this article I shall assume that you have already read the article entitled Datagrid Highlight a Row With Click Through...

Binding a Datagrid to an Access Database
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Adding Data to a DropDownList
The aim of this article is to answer the question 'How do I add items to a DropDownList?' Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP...

Getting Current Date Time
In classic ASP we had now() which would return the current date and time. For asp.net this no longer exists. So what should we use...

Test if File Exists
Sometimes, in order to reduce our chance of error, when working with the filesystem in ASP.NET, we need to determine wether a file exists before performing an action on it. The following short piece of code will enable us to test whether a file exists...

Using Javascript with ASP.NET Form Elements
Adding simple pieces of Javascript to an Asp.net page can be acheived by adding to the attributes of the particular imagebutton or linkbutton. if its normal ASP.Net Button then you can...

Regular Expressions
In the table below we list the characters used in .Net regular expressions, together with their meaning, But first...

Authentication in Asp.net
Forms authentication in ASP.Net is far more easier and safe than Asp 3. It is possible to place a web.config file in any directory of a web site.Therefore, we are able to make most of a web site public, whilst providing authentication on, say, one directory...

Discussion Forums

General ASP.NET

.Net Programming

cSharp Home

Sql Server Home

Javascript / Client Side Development

IT Jobs

Ajax Programming

Ruby on Rails Development

Perl Programming

C Programming Language

C++ Programming

Python Programming Language

Laptop Suggestions?

TCL Scripting

Fortran Programming

Scheme Programming

5. Calendar

FAQ Home
   5.1 How to display multiple dates selected in Calendar Control?
   5.2 How to reset the selected date in the calendar control?
   5.3 How to Customize Individual Days in a Calendar Web Server Control?
   5.4 Is there a way to click an image and let the calendar Control appear?
   5.5 How to Programmatically change backgroundcolor of a Calendar Control using Dropdown List?
   5.6 How can I change the month and Weekdays to Japanese characters for a Calendar Control?
   5.7 How can I use a Calendar Control to show specific dates highlighted and display relevant data for that date?
   5.8 How to clear the Calendar Control Selection?
   5.9 How can I set the Selection of the Calendar Control to date or week or month?
   5.10 How can I display the calendar control in different languages according to the navigator culture?
   5.11 How to display full day names in a Calendar Control?
   5.12 How to hide the WeekDay Header in the Calendar control?
   5.13 How to hide "other months" in a Calendar Control?
   5.14 How to highlight today's date in Calendar Control in different color?
   5.15 How can I use a Calendar Control in readonly mode. i.e no links for the day and month cells.
   5.16 How to change the Calendar Dates using a Dropdownlist?



5.1 How to display multiple dates selected in Calendar Control?


Set the SelectionMode property of Calendar Control to DayWeek/ DayWeekMonth.
Code for the OnSelectionChanged as follows:

VB.NET


Dim day As DateTime
Dim strval As String
For Each day In Calendar1.SelectedDates
     strval += (day.Date.ToShortDateString() & "<br>")
Next
Response.Write(strval)


C#


string strval="" ;
foreach (DateTime day in Calendar1.SelectedDates)
{
     strval += (day.Date.ToShortDateString() + "<br>");
}
Response.Write(strval);
}



5.2 How to reset the selected date in the calendar control?


VB.NET


Calendar1.VisibleDate = DateTime.Today
Calendar1.SelectedDates.Clear()


C#


Calendar1.VisibleDate = DateTime.Today;
Calendar1.SelectedDates.Clear();



5.3 How to Customize Individual Days in a Calendar Web Server Control?


Refer Customizing Individual Days in a Calendar Web Server Control


5.4 Is there a way to click an image and let the calendar Control appear?


Refer to these articles:

Other links

 


5.5 How to Programmatically change backgroundcolor of a Calendar Control using Dropdown List?



<asp:Calendar id="Calendar1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 48px" runat="server"></asp:Calendar>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 24px"
     runat="server" AutoPostBack="True">
     <asp:ListItem Value="Red">Red</asp:ListItem>
     <asp:ListItem Value="Green">Green</asp:ListItem>
     <asp:ListItem Value="Blue">Blue</asp:ListItem>
</asp:DropDownList>


VB.NET


Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
     Dim colorName As String = DropDownList1.SelectedItem.Text
     Dim objBackColor As System.Drawing.Color = System.Drawing.Color.FromName(colorName)
     Calendar1.BackColor = objBackColor
End Sub


C#


private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
     string colorName = DropDownList1.SelectedItem.Text;
     System.Drawing.Color objBackColor = System.Drawing.Color.FromName(colorName);
     Calendar1.BackColor = objBackColor;
}



5.6 How can I change the month and Weekdays to Japanese characters for a Calendar Control?


Set the Culture= "ja-JP" for the Page.

  • ASP.NET pages support Culture and UICulture attributes to support independent localized pages.
  • Controls on pages can pick the culture of the page and can render culture-dependent content.

 


5.7 How can I use a Calendar Control to show specific dates highlighted and display relevant data for that date?



<asp:Calendar id="Calendar1" OnDayRender ="CalDayRender" runat="server"></asp:Calendar>



Dim ds As DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     'Put user code to initialize the page here
     'Fill the DataSet
End Sub

Protected Sub CalDayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)
     Dim strName As New StringBuilder
     strName.Append("
")
     Dim theDay As DateTime = e.Day.Date
     Dim sql As String = "hiredate='" + DateTime.Parse(theDay.ToString("d")) + "' "
     Dim dr As DataRow() = ds.Tables(0).Select(sql)
     Dim drRow As DataRow
     For Each drRow In dr
      strName.Append("
      e.Cell.BackColor = Color.Teal
      e.Cell.ForeColor = Color.Wheat
     Next drRow
     strName.Append("")
     e.Cell.Controls.Add(New LiteralControl(strName.ToString()))
End Sub 'CalDayRender


C#


DataSet ds ;
private void Page_Load(object sender, System.EventArgs e)
{
     // Put user code to initialize the page here
     //Populate the DataSet
}

protected void CalDayRender(object sender, DayRenderEventArgs e)
{
     StringBuilder strName = new StringBuilder();
     strName.Append("
");
     DateTime theDay = e.Day.Date;
     string sql ="hiredate='" + DateTime.Parse ( theDay.ToString("d")) + "' ";
     DataRow [] dr = ds.Tables[0].Select(sql);
     foreach(DataRow drRow in dr)
     {
          strName.Append("
          e.Cell.BackColor = Color.Teal;
          e.Cell.ForeColor = Color.Wheat;
     }
     strName.Append("");
     e.Cell.Controls.Add(new LiteralControl(strName.ToString()));
}



5.8 How to clear the Calendar Control Selection?


VB.NET


Calendar1.SelectedDate =new DateTime()


C#


Calendar1.SelectedDate =new DateTime();



5.9 How can I set the Selection of the Calendar Control to date or week or month?


Set the SelectionMode =DayWeekMonth

You can set it to any of the following:

  • Day
  • DayWeek
  • DayWeekMonth
  • None

 


5.10 How can I display the calendar control in different languages according to the navigator culture?


Use namespace

  • System.Threading
  • System.Globalization

 


<p>
<asp:dropdownlist id="DropDownlist1" runat="server"></asp:dropdownlist></p>
<p>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></p>
<asp:calendar id="Calendar1" runat="server"></asp:calendar>


VB.NET


Dim userLang() As String
Dim strLang As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     'Put user code to initialize the page here
     userLang = Request.UserLanguages
     ViewState("userLanguage") = userLang(userLang.GetUpperBound(0))
     If ViewState("userLanguage") = "" Then
          ViewState("userLanguage") = "en-US"
     End If
     Dim ci As CultureInfo
     For Each ci In CultureInfo.GetCultures(CultureTypes.AllCultures)
          If Not ci.IsNeutralCulture Then
          DropDownlist1.Items.Add(ci.ToString)
          End If
     Next
     Dim dtNow As Date = DateTime.Now
     strLang = ViewState("userLanguage")
     Thread.CurrentThread.CurrentUICulture = New CultureInfo(strLang, False)
     Thread.CurrentThread.CurrentCulture = New CultureInfo(strLang)
     Calendar1.SelectedDate = dtNow
     Calendar1.VisibleDate = dtNow
End Sub

Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
     strLang = ViewState("userLanguage")
     Thread.CurrentThread.CurrentUICulture = New CultureInfo(strLang, False)
     Thread.CurrentThread.CurrentCulture = New CultureInfo(strLang)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     strLang = DropDownlist1.SelectedItem.Text
     ViewState("userLanguage") = strLang
     Thread.CurrentThread.CurrentUICulture = New CultureInfo(strLang, False)
     Thread.CurrentThread.CurrentCulture = New CultureInfo(strLang)
End Sub


C#


string[] userLang;
string strLang;
private void Page_Load(object sender, System.EventArgs e)
{
     // Put user code to initialize the page here
     userLang = Request.UserLanguages;
     ViewState["userLanguage"] = userLang[userLang.GetUpperBound(0)];
     if( ViewState["userLanguage"].ToString () == "" )
     {
          ViewState["userLanguage"] = "en-US";
     }
     foreach(CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
     {
          if(!ci.IsNeutralCulture)
          {
               DropDownlist1.Items.Add(ci.ToString());
          }
     }
     DateTime dtNow = DateTime.Now;
     strLang =(string) ViewState["userLanguage"];
     Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLang, false);
     Thread.CurrentThread.CurrentCulture =new CultureInfo(strLang);
     Calendar1.SelectedDate = dtNow;
     Calendar1.VisibleDate = dtNow;
}

private vo