How to moving a list to codebehind?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Johnson
    New Member
    • Oct 2010
    • 97

    #1

    How to moving a list to codebehind?

    Hi,

    I have some markup on a page which I need to move to a code behind and I'm not quite sure how to do it

    An example is this

    Code:
    <asp:DropDownList ID="YearList" runat="server">
             <asp:ListItem Value="1940" Title="1940" />
             <asp:ListItem Value="1950" Title="1950" />
             <asp:ListItem Value="1960" Title="1960" />
             <asp:ListItem Value="1970" Title="1970" />
    Would the codebehind become

    Code:
    With YearList
      .Value(0)="1940"
      .Text(0)="1940"
    End With
    or would it be something else?

    Thanks

    PJ
    Last edited by Paul Johnson; Jan 25 '11, 02:57 PM. Reason: Formatting
  • Dotneticus
    New Member
    • Jan 2011
    • 2

    #2
    Will the list values be coming from a database or just will it be just a predefined list?

    Comment

    • Paul Johnson
      New Member
      • Oct 2010
      • 97

      #3
      predefined

      Comment

      • Dotneticus
        New Member
        • Jan 2011
        • 2

        #4
        You could use:

        Dropdownlist.It ems.Add(New ListItem("1940" , "1940")) - If the value is different from the displayed item.

        If they are the same, you can use:

        Dropdownlist.It ems.Add("1940")

        Comment

        Working...