Navigating to a specific month and an year in an asp.net calendar control Part 111

  • دعنا نشارك هذا :
ترتيب الدرس : 111
المدة : 00:13:05
التحكم :
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/01/navigating-to-specific-month-and-year.html

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation1

Slides
http://csharp-video-tutorials.blogspot.com/2013/08/part-111-navigating-to-specific-month.html

All ASP .NET Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-aspnet-video-tutorial.html

All ASP .NET Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-slides.html

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view1&sortdd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

This question was asked by 3 to 4 youtube subscribers of my channel. There are several reasons or situations in real time, where we need to navigate to a specific month and an year in an asp.net calendar control. For example, if the date of birth of a person is in the year 1960, we may have to click on the calendar control several times to navigate to that year.

Let's see, how to skip months and years, so that the dates that are too far in the past or future can be easily selected. To achieve this

For the HTML and code samples used in the demo please visit my blog at the following link
http://csharp-video-tutorials.blogspot.com/2013/01/navigating-to-specific-month-and-year.html

Copy and paste the following code in the code-behind file
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadYears();
LoadMonths();
}
}

private void LoadMonths()
{
DataSet dsMonthsnew DataSet();
dsMonths.ReadXml(Server.MapPath("~/Data/Months.xml"));

DropDownList2.DataTextField"Name";
DropDownList2.DataValueField"Number";

DropDownList2.DataSourcedsMonths;
DropDownList2.DataBind();
}

private void LoadYears()
{
DataSet dsYearsnew DataSet();
dsYears.ReadXml(Server.MapPath("~/Data/Years.xml"));

DropDownList1.DataTextField"Number";
DropDownList1.DataValueField"Number";

DropDownList1.DataSourcedsYears;
DropDownList1.DataBind();
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int yearConvert.ToInt16(DropDownList1.SelectedValue);
int monthConvert.ToInt16(DropDownList2.SelectedValue);
Calendar1.VisibleDatenew DateTime(year, month, 1);
Calendar1.SelectedDatenew DateTime(year, month, 1);
}

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
int yearConvert.ToInt16(DropDownList1.SelectedValue);
int monthConvert.ToInt16(DropDownList2.SelectedValue);
Calendar1.VisibleDatenew DateTime(year, month, 1);
Calendar1.SelectedDatenew DateTime(year, month, 1);
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Calendar1.SelectedDate.ToShortDateString());
}

At this point, run the project and you should be able to skip to any month and year in an asp.net calendar control. This code can be encapsulated in an user control, and reused anywhere in the entire project.

سيتم تفعيل التعليقات قريبا

y
Sep 23, 2020 07:32:26
youtube