2009-04-06 13 views
0

Ich habe lächerlich Problem mit Dropdown-Liste. Durch for-Schleife habe ich Drop-Down-Wert für Tag, Monat und Jahr eingefügt. Aber wenn ich das Formular einreiche, nachdem ich den Tag, den Monat und das Jahr aus der Dropdownliste ausgewählt habe, wird der Wert des Listenelements nach jedem Einreichen neu indiziert.Ex.Für den 1. bis 31. Tag, den Monat 1 bis 12, das Jahr 1970 bis 2009.Nach dem Abschicken des Formulars Der Listeneintrag wird für jede Dropdown-Liste doppelt. Wie in der Tag-Dropdown-Liste vor dem Absenden 1 bis 31 nach dem Absenden. Wenn ich die Dropdown-Liste überprüfe, wird der Wert zwei Mal 1 bis 31 sein. Ich meine 1 bis 31 wieder 1 bis 31 innerhalb der Liste für jeden dropdownlist.Here ist mein Code: aspx:Brauchen Sie Hilfe in Dropdown-Steuerelement

<asp:DropDownList ID="DropDownDay" runat="server"> 
        <asp:ListItem Text="Select Day"></asp:ListItem>     
</asp:DropDownList> 
<asp:DropDownList ID="DropDownMonth" runat="server"> 
        <asp:ListItem Text="Select Month"></asp:ListItem> 
</asp:DropDownList> 
        <asp:DropDownList ID="DropDownYear" runat="server"> 
        <asp:ListItem Text="Select Year"></asp:ListItem>     
    </asp:DropDownList> 
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; 

Danke, Sumit

+0

Mit dem Codebeispiel die Formatierung Taste (es sieht aus wie: ‚101010‘) Code zu formatieren. Es ist sehr schwer einen unformatierten Blog so zu lesen. – Calvin

Antwort

1

Sie wahrscheinlich nicht für Page.IsPostBack Option werden überprüft

wenn es wahr ist, dann repopulate NICHT Ihre Dropdown-Listen

+0

Hallo Herr Raj absolut richtig. Vielen Dank für Ihre Antwort. – user59637

+0

Mann, danke ist nicht genug. Sie müssen für meine Antwort stimmen und sie als die richtige Antwort akzeptieren, wenn sie Ihr Problem gelöst hat – Raj