Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 28, 2013 08:03 AM by ramiramilu
Member
141 Points
553 Posts
Feb 27, 2013 09:35 AM|LINK
hello friends.
i need to fill dropdown for month. as selected month, previous month and next month. in year current year should be display. its working.
for example current month is jan then in my month dropdown month is : december,jan(select), feb and year is 2013
now i want if any one select december previous year should be display.year automatically change to 2012. also working.
below code is not working for oct, nov,dec, 2013. now i selecting december it produces wrong result. dec 2012
below is my code:
page load:
if (!IsPostBack) {
ddlmonth.Items.Insert(0, new ListItem("Issue Month", "0")); int j;
DateTime month = DateTime.Now; month = month.AddMonths(-1); for (j = 1; j < 4; j++) {
ddlmonth.Items.Insert(j, new ListItem(month.ToString("MMMM"))); month = month.AddMonths(1); } DateTime cmonth = DateTime.Now; ddlmonth.SelectedIndex = (ddlmonth.Items.IndexOf(ddlmonth.Items.FindByText(cmonth.ToString("MMMM")))); ddlyear.Items.Insert(0, new ListItem(DateTime.Now.Year.ToString())); ddlyear.Enabled = false;
}
protected void ddlmonth_SelectedIndexChanged(object sender, EventArgs e) {
if (ddlmonth.SelectedItem.Value.ToString() == "December") { ddlyear.Items.Insert(0, new ListItem(DateTime.Now.AddYears(-1).ToString("yyyy"))); // ddlyear.SelectedItem.Value = DateTime.Now.AddYears(-1).ToString("yyyy"); ddlyear.SelectedIndex = 0; ddlyear.Enabled = false;}
else { ddlyear.Items.Insert(0, new ListItem(DateTime.Now.Year.ToString())); ddlyear.SelectedIndex = 0; ddlyear.Enabled = false; }}
Feb 27, 2013 09:40 AM|LINK
i also want to acheive this using jquery insted of postback.
Contributor
2998 Points
572 Posts
Feb 27, 2013 10:16 AM|LINK
I think you are confused in what you supposed to do.
How can you decide after user selects december, it is Dec-2012 / Dec-2013.
Do simple thing use two dropdowns of Month and Year and let user choose Month and Year among them.
Or let user choose any month and consider it as of 2013, which will again create problem for back dated entries. Use above approach..
Feb 27, 2013 10:53 AM|LINK
yes sujeet u r right this thing i also told to my senior bt he is not accepting and and saying he want this at any cost.
5020 Points
955 Posts
Feb 27, 2013 11:02 AM|LINK
Hi,
I got your problem, you can get this done by checking the selected index and then check the name of the month. Try as below,
if (ddlmonth.SelectedItem.Value.ToString() == "December" && ddlmonth.SelectedIndex==0) { ddlyear.Items.Insert(0, new ListItem(DateTime.Now.AddYears(-1).ToString("yyyy"))); // ddlyear.SelectedItem.Value = DateTime.Now.AddYears(-1).ToString("yyyy"); ddlyear.SelectedIndex = 0; ddlyear.Enabled = false;}
Feb 28, 2013 07:48 AM|LINK
how above do by jquery.
All-Star
95245 Points
14072 Posts
Feb 28, 2013 08:03 AM|LINK
use jquery cascading dropdowns - http://www.ryanmwright.com/2010/10/13/cascading-drop-down-in-jquery/
thanks,
atul2430
Member
141 Points
553 Posts
fill Dropdown on select on other
Feb 27, 2013 09:35 AM|LINK
hello friends.
i need to fill dropdown for month. as selected month, previous month and next month. in year current year should be display. its working.
for example current month is jan then in my month dropdown month is : december,jan(select), feb and year is 2013
now i want if any one select december previous year should be display.year automatically change to 2012. also working.
below code is not working for oct, nov,dec, 2013. now i selecting december it produces wrong result. dec 2012
below is my code:
page load:
if (!IsPostBack)
{
ddlmonth.Items.Insert(0, new ListItem("Issue Month", "0"));
int j;
DateTime month = DateTime.Now;
month = month.AddMonths(-1);
for (j = 1; j < 4; j++)
{
ddlmonth.Items.Insert(j, new ListItem(month.ToString("MMMM")));
month = month.AddMonths(1);
}
DateTime cmonth = DateTime.Now;
ddlmonth.SelectedIndex = (ddlmonth.Items.IndexOf(ddlmonth.Items.FindByText(cmonth.ToString("MMMM"))));
ddlyear.Items.Insert(0, new ListItem(DateTime.Now.Year.ToString()));
ddlyear.Enabled = false;
}
protected void ddlmonth_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlmonth.SelectedItem.Value.ToString() == "December")
{
ddlyear.Items.Insert(0, new ListItem(DateTime.Now.AddYears(-1).ToString("yyyy")));
// ddlyear.SelectedItem.Value = DateTime.Now.AddYears(-1).ToString("yyyy");
ddlyear.SelectedIndex = 0;
ddlyear.Enabled = false;}
else
{
ddlyear.Items.Insert(0, new ListItem(DateTime.Now.Year.ToString()));
ddlyear.SelectedIndex = 0;
ddlyear.Enabled = false;
}}
atul2430
Member
141 Points
553 Posts
Re: fill Dropdown on select on other
Feb 27, 2013 09:40 AM|LINK
i also want to acheive this using jquery insted of postback.
Sujeet Saste
Contributor
2998 Points
572 Posts
Re: fill Dropdown on select on other
Feb 27, 2013 10:16 AM|LINK
I think you are confused in what you supposed to do.
How can you decide after user selects december, it is Dec-2012 / Dec-2013.
Do simple thing use two dropdowns of Month and Year and let user choose Month and Year among them.
Or let user choose any month and consider it as of 2013, which will again create problem for back dated entries. Use above approach..
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
atul2430
Member
141 Points
553 Posts
Re: fill Dropdown on select on other
Feb 27, 2013 10:53 AM|LINK
yes sujeet u r right this thing i also told to my senior bt he is not accepting and and saying he want this at any cost.
prabu.raveen...
Contributor
5020 Points
955 Posts
Re: fill Dropdown on select on other
Feb 27, 2013 11:02 AM|LINK
Hi,
I got your problem, you can get this done by checking the selected index and then check the name of the month. Try as below,
if (ddlmonth.SelectedItem.Value.ToString() == "December" && ddlmonth.SelectedIndex==0)
{
ddlyear.Items.Insert(0, new ListItem(DateTime.Now.AddYears(-1).ToString("yyyy")));
// ddlyear.SelectedItem.Value = DateTime.Now.AddYears(-1).ToString("yyyy");
ddlyear.SelectedIndex = 0;
ddlyear.Enabled = false;}
else
{
ddlyear.Items.Insert(0, new ListItem(DateTime.Now.Year.ToString()));
ddlyear.SelectedIndex = 0;
ddlyear.Enabled = false;
}}
atul2430
Member
141 Points
553 Posts
Re: fill Dropdown on select on other
Feb 28, 2013 07:48 AM|LINK
how above do by jquery.
ramiramilu
All-Star
95245 Points
14072 Posts
Re: fill Dropdown on select on other
Feb 28, 2013 08:03 AM|LINK
use jquery cascading dropdowns - http://www.ryanmwright.com/2010/10/13/cascading-drop-down-in-jquery/
thanks,
JumpStart