asp dropdownlist - add numbers 1-15 to list

前端 未结 5 840
日久生厌
日久生厌 2021-01-14 13:00

Is there a way of adding the values 1-15 to an asp dropdownlist without having to do each one individually...

I currently have:

ddlAdults.Items.Inser         


        
相关标签:
5条回答
  • 2021-01-14 13:12
    For i As Integer = 1 To 15
        ddlAdults.Items.Add(new ListItem(i.ToString(), i.ToString()))
    Next i
    
    0 讨论(0)
  • 2021-01-14 13:20

    Use a loop?

    Like for loop or a foreach loop.

    http://en.wikipedia.org/wiki/For_loop

    or http://en.wikipedia.org/wiki/Foreach

    That should help u, as I dont know what language u're programming in..

    0 讨论(0)
  • 2021-01-14 13:23
    ddlAdults.DataSource = Enumerable.Range(1, 15)
    ddlAdults.DataBind()
    
    0 讨论(0)
  • 2021-01-14 13:31
    //cmbDay.Items.Insert(0, new ListItem("1"));
    //cmbDay.Items.Insert(1, new ListItem("2"));
    //cmbDay.Items.Insert(2, new ListItem("3"));
    //cmbDay.Items.Insert(3, new ListItem("4"));
    
    for( i=0;i<15;i++)
        {
           cmbDay.Items.Insert(i,new ListItem(i.ToString()));
        } 
    
    0 讨论(0)
  • 2021-01-14 13:34
    for(int i=0;i<15;i++)
    {
       ddlAdults.Items.Insert(i, new ListItem((i+1).toString(), (i+1).toString()));
    }
    
    0 讨论(0)
提交回复
热议问题