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:
| ||||||||
VulpesPosted Jul 11, 2013, 9:19 AM
samantaPosted Jul 12, 2013, 2:50 AM
samantaPosted Jul 11, 2013, 8:19 AM
please send me the code
VulpesPosted Jul 11, 2013, 8:14 AM
So, for example, when we are in August, it should show August, September and October.
samantaPosted Jul 11, 2013, 8:05 AM
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
VulpesPosted Jul 10, 2013, 9:04 AM
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();
}
}
samantaPosted Jul 10, 2013, 8:46 AM
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.
VulpesPosted Jul 10, 2013, 8:41 AM
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?
samantaPosted Jul 10, 2013, 8:27 AM
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
VulpesPosted Jul 10, 2013, 8:16 AM
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?
samantaPosted Jul 10, 2013, 8:01 AM
VulpesPosted Jul 10, 2013, 7:41 AM
samantaPosted Jul 10, 2013, 7:23 AM
when i run the code the firstdown shows the option "Junuary" but i want just ---Month--
below this month shoulb be display
samantaPosted Jul 10, 2013, 7:21 AM
Sanjeeb LenkaPosted Jul 10, 2013, 7:08 AM
Sharad GuptaPosted Jul 10, 2013, 7:07 AM
Code Behind
samantaPosted Jul 10, 2013, 6:56 AM
VulpesPosted Jul 10, 2013, 6:33 AM
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.
samantaPosted Jul 10, 2013, 6:03 AM
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:
Sanjeeb LenkaPosted Jul 10, 2013, 5:52 AM
samantaPosted Jul 10, 2013, 5:45 AM
sir its code to just select from dropdownlist and submit but it does't setisfy my condition
Sanjeeb LenkaPosted Jul 10, 2013, 5:40 AM
http://aspsnippets.com/Articles/Select-Day-Month-and-Year-Date-from-DropDownList-in-ASPNet.aspx