DropDownLists, ListBoxs, and CheckBoxLists

Discussion in 'ASP .Net Web Controls' started by Pranav Shah, Jul 25, 2003.

  1. Pranav Shah

    Pranav Shah Guest

    I have a few DropDownLists, ListBoxs, and CheckBoxLists and assume for
    the sake of argument that I want to put the same data in all of these.
    Is there a way that I can just pass the name of the controls and
    populate them in a common method.



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Pranav Shah, Jul 25, 2003
    #1
    1. Advertising

  2. Hi

    You can add items programmatically at run time to all
    list Web server controls: ListBox, DropDownList,
    CheckBoxList, and RadioButtonList.

    You can add items to a list Web server control in these
    ways:

    To add items programmatically

    Create a new object of type ListItem and set its Text and
    Value properties.

    Call the Add method of the control's Items collection and
    pass it the new object.

    The following example shows how to add ListItem objects
    to a ListBox control, but the procedure is identical for
    all list Web server controls.

    ' Visual Basic
    Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles Button1.Click
    Me.ListBox1.Items.Add(New ListItem("Carbon", "C"))
    Me.ListBox1.Items.Add(New ListItem("Oxygen", "O"))
    End Sub

    // C#
    public void Button1_Click (object sender,
    System.EventArgs e)
    {
    this.ListBox1.Items.Add(new ListItem("Carbon", "C"));
    this.ListBox1.Items.Add(new ListItem("Oxygen", "O"));
    }


    HTH
    Ravikanth

    >-----Original Message-----
    >I have a few DropDownLists, ListBoxs, and CheckBoxLists

    and assume for
    >the sake of argument that I want to put the same data in

    all of these.
    >Is there a way that I can just pass the name of the

    controls and
    >populate them in a common method.
    >
    >
    >
    >*** Sent via Developersdex http://www.developersdex.com

    ***
    >Don't just participate in USENET...get rewarded for it!
    >.
    >
    Ravikanth[MVP], Jul 25, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trint Smith

    Text in listboxs disappear...

    Trint Smith, Feb 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    340
    Trint Smith
    Feb 17, 2004
  2. =?Utf-8?B?ZGVlcGFr?=

    listboxs and javascript problem

    =?Utf-8?B?ZGVlcGFr?=, Feb 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    325
    =?Utf-8?B?ZGVlcGFr?=
    Feb 15, 2005
  3. =?Utf-8?B?U2FuZHk=?=

    Client side code for two checkboxlists

    =?Utf-8?B?U2FuZHk=?=, Jun 8, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    456
    =?Utf-8?B?U2FuZHk=?=
    Jun 9, 2005
  4. Michael Groeger

    Validation of CheckBoxLists

    Michael Groeger, Sep 29, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    483
    S. Justin Gengo
    Sep 29, 2005
  5. KBuser
    Replies:
    1
    Views:
    824
    Brian
    Apr 11, 2006
Loading...

Share This Page