tags:

views:

122

answers:

1

Hi all, I have ridiculous problem with dropdownlist.Through for loop i have inserted dropdown value for Day,Month and Year. But when i am submitting the form after selecting the Day,Month and Year from Dropdownlist,the list item value is reindexing after each submitting.Ex.For Day 1 to 31,Month 1 to 12, year 1970 to 2009.After Submitting the form the list item is becoming double for each dropdownlist.Like in day dropdownlist before submiting it was 1 to 31 after submitting if i check dropdownlist the value will be two times 1 to 31 I mean 1 to 31 again 1 to 31 inside the listitem it happens for each dropdownlist.Here is my code: aspx:

aspx.cs: //Inserting day in the day dropdown list. for (int i = 1; i <=31; i++) { ListItem item = new ListItem(); item.Value = i.ToString(); DropDownDay.Items.Add(item.Value); } //Inserting month in the month dropdown list. for (int i = 1; i <=12; i++) { ListItem item = new ListItem(); item.Value = i.ToString(); DropDownMonth.Items.Add(item.Value); } //Inserting year in the year dropdown list. for (int i = 1970; i <=2009; i++) { ListItem item = new ListItem(); item.Value = i.ToString(); DropDownYear.Items.Add(item.Value); } string day = DropDownDay.Text; string month = DropDownMonth.Text; string year = DropDownYear.Text; After adding i have set: DropDownDay.SelectedIndex = 0; DropDownMonth.SelectedIndex = 0; DropDownYear.SelectedIndex = 0;

Thanks, Sumit

+1  A: 

you probably are not checking for Page.IsPostBack option

if it is true, then DO NOT REPOPULATE your drop down lists

Raj
Hi Mr.Raj absolutely u r right.Thanks for your reply.
dude, thanks is not enough. you need to vote up for my answer and accept it as the right answer if it has solved your problem
Raj