related with dropdownlist [Resolved]

Posted by Amritha444 under C# on 10/13/2010 | Points: 10 | Views : 2036 | Status : [Member] | Replies : 5
I filled months jan,feb.. in a dropdownlist i want current month as default value ie,selected value..
Eg: I want oct as selected value in my drop downlist.How to silve this
Thanks in Advance




Responses

Posted by: Vpramodg on: 10/13/2010 [Member] Starter | Points: 50

Up
0
Down

Resolved
hai

You may please use the above mentioned link
http://www.dotnetfunda.com/codes/code987-how-to-populate-month-name-in-dropdownlist-in-aspnet.aspx

and paste this code in the page load you will get the solution.

dropDown1.SelectedIndex =(int) DateTime.Now.Month-1; ;



Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 10/13/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Assuming your dropdown has value as "October", you can make it default selected if you write following code in the page load

dropDown1.SelectedValue = "October";


If your dropdown has month digit as value, then write following code in the page load

        dropDown1.SelectedValue = "10";


This post will help you populate the month name easily in case you are using some other mechanism to populate the month name in the dropdown. http://www.dotnetfunda.com/codes/code987-how-to-populate-month-name-in-dropdownlist-in-aspnet.aspx

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 10/13/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Amritha,

How to fill your data into DropDownList? Are you using Enum (or) DataTable (or) Item Property?


Thanks,
T.Saravanan

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amritha444 on: 10/13/2010 [Member] Starter | Points: 25

Up
0
Down
I add months as items.i want selected month according to current month.It changing in every month so i cant give static values to drop down list..

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 10/13/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Amritha,

Its the critical one because if we set our system month into our dropdownlist means if any one change the system date means automatically change in our dropdown.
So my suggestion is to get the month from server after add the items into dropdownlist then to set the month is selected value in your dropdown.

Note : In your Server Date is Current Date.

In SqlServer using this query means you get the current month
 Select DateName(Month,GetDate()) 



Cheers:)

Thanks,
T.Saravanan

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response