2) if i select month in first dropdownlist in next dropdownlist current date and year must be displayed.
3) code must be asp.net c# web application only
for example you can check below link.
http://www.toyotabharat.com/inen/forms/testdrive.aspx
just select any state in that page check
Preferred Date:
| ||||||||

VulpesRank #55 · 29.2K reputationPosted Jul 11, 2013, 5:19 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 10, 2013, 1:40 AM EDT
http://aspsnippets.com/Articles/Select-Day-Month-and-Year-Date-from-DropDownList-in-ASPNet.aspx
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 1:45 AM EDT
sir its code to just select from dropdownlist and submit but it does't setisfy my condition
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 10, 2013, 1:52 AM EDT
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 2:03 AM EDT
i have 3 dropdown list
first dropdownlistname month.
secand dropdownlistname day.
third dropdownlistname year.
if i select one option from month for example july than currrent day and year must be display
if i select other than july than date must show day from 1 to end and year
for example you can check below link.
http://www.toyotabharat.com/inen/forms/testdrive.aspx
just select any state in that page check
Preferred Date:
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2013, 2:33 AM EDT
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] months =
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
DropDownList1.DataSource = months;
DropDownList1.DataBind();
DropDownList1.SelectedIndex = 0;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int month = DropDownList1.SelectedIndex + 1;
int year = DateTime.Today.Year;
int daysInMonth = DateTime.DaysInMonth(year, month);
DropDownList2.DataSource = Enumerable.Range(1, daysInMonth);
DropDownList2.DataBind();
if (month == DateTime.Today.Month) DropDownList2.SelectedIndex = DateTime.Today.Day - 1;
int[] years = { DateTime.Today.Year };
DropDownList3.DataSource = years;
DropDownList3.DataBind();
}
}
AutoPostBack for the DropDownLists should, of course, be set to true.
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 2:56 AM EDT
Sharad GuptaRank #111 · 20K reputationPosted Jul 10, 2013, 3:07 AM EDT
Code Behind
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 10, 2013, 3:08 AM EDT
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 3:21 AM EDT
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 3:23 AM EDT
when i run the code the firstdown shows the option "Junuary" but i want just ---Month--
below this month shoulb be display
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2013, 3:41 AM EDT
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 4:01 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2013, 4:16 AM EDT
However, does it follow from this that, if the user selects a month before the current month, the year should show 2014 rather than 2013?
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 4:27 AM EDT
if system date is december 2013 and if we select january means than the year must be changed to 2014
one more thing if i don't want months before the current month than how to implement that
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2013, 4:41 AM EDT
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 0)
{
DropDownList2.DataSource = new string[] { "--Day--" };
DropDownList2.DataBind();
DropDownList3.DataSource = new string[] { "--Year--" };
DropDownList3.DataBind();
return;
}
int month = DropDownList1.SelectedIndex;
int year = DateTime.Today.Year;
if (month < DateTime.Today.Month) year++;
int daysInMonth = DateTime.DaysInMonth(year, month);
if (month == DateTime.Today.Month)
{
int today = DateTime.Today.Day;
DropDownList2.DataSource = Enumerable.Range(today, daysInMonth - today + 1);
}
else
{
DropDownList2.DataSource = Enumerable.Range(1, daysInMonth);
}
DropDownList2.DataBind();
int[] years = { year };
DropDownList3.DataSource = years;
DropDownList3.DataBind();
}
On the second point, do you mean that only months from the current month to December would be shown in the first DropDownList and so the year would always be the current year?
samantaRank #3,157 · 454 reputationPosted Jul 10, 2013, 4:46 AM EDT
in first dropdownlist it must contain current month to end and when crosses december it must show all months with year 2014
i got really good answer from you.thank you very much.please send that code also.
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2013, 5:04 AM EDT
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DateTime dt = DateTime.Today;
int month = dt.Month;
int year = dt.Year;
string[] months = new string[14 - month];
months[0] = "--Month--";
int i = 1;
while (dt.Year == year)
{
months[i] = dt.ToString("MMMM");
dt = dt.AddMonths(1);
i++;
}
DropDownList1.DataSource = months;
DropDownList1.DataBind();
DropDownList1.SelectedIndex = 0;
DropDownList2.DataSource = new string[] { "--Day--" };
DropDownList2.DataBind();
DropDownList3.DataSource = new string[] { "--Year--" };
DropDownList3.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 0)
{
DropDownList2.DataSource = new string[] { "--Day--" };
DropDownList2.DataBind();
DropDownList3.DataSource = new string[] { "--Year--" };
DropDownList3.DataBind();
return;
}
int month = DropDownList1.SelectedIndex + DateTime.Today.Month - 1;
int year = DateTime.Today.Year;
int daysInMonth = DateTime.DaysInMonth(year, month);
if (month == DateTime.Today.Month)
{
int today = DateTime.Today.Day;
DropDownList2.DataSource = Enumerable.Range(today, daysInMonth - today + 1);
}
else
{
DropDownList2.DataSource = Enumerable.Range(1, daysInMonth);
}
DropDownList2.DataBind();
int[] years = { year };
DropDownList3.DataSource = years;
DropDownList3.DataBind();
}
}
samantaRank #3,157 · 454 reputationPosted Jul 11, 2013, 4:05 AM EDT
i want in firstdropdownlist it must show only 3 months like july,August,October.
as we crosses the october dropdownlist must show next three option november December(year will be 2013)and January with year 2014
VulpesRank #55 · 29.2K reputationPosted Jul 11, 2013, 4:14 AM EDT
So, for example, when we are in August, it should show August, September and October.
samantaRank #3,157 · 454 reputationPosted Jul 11, 2013, 4:19 AM EDT
please send me the code
samantaRank #3,157 · 454 reputationPosted Jul 11, 2013, 10:50 PM EDT