Welcome to Dream.In.Code
Become an Expert!

Join 149,798 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,819 people online right now. Registration is fast and FREE... Join Now!




Populating a drop-down list

 
Reply to this topicStart new topic

Populating a drop-down list

macker
6 Feb, 2007 - 01:56 PM
Post #1

New D.I.C Head
*

Joined: 2 Feb, 2007
Posts: 4



Thanked: 1 times
My Contributions
I was wondering if anyone knows a relatively simple way to populate a drop-down list.

I cannot use the object data bindings, I am currently required to do it in the code, using the databind() commands.

I would like to populate this drop-down with the use of a Stored Proc.....

I am using Visual Studio 2005, SQL Server 2005, and ASP.NET 2.0

If anyone could give me some tips, that would be great!

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Populating A Drop-down List
7 Feb, 2007 - 03:32 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Just create a ListItem so that you can create the items to be added to the list. Then add them like the following example.

This will populate a list of 4 items in the drop down list. They are All, Titles, Actor, Description

CODE

        Dim ddlItem As ListItem

        If Not IsPostBack Then
            ddlFilter.Items.Clear()

            ddlItem = New ListItem
            ddlItem.Text = "All"
            ddlItem.Value = "All"
            ddlFilter.Items.Add(ddlItem)

            ddlItem = New ListItem
            ddlItem.Text = "Titles"
            ddlItem.Value = "MovieTitle"
            ddlFilter.Items.Add(ddlItem)

            ddlItem = New ListItem
            ddlItem.Text = "Actor"
            ddlItem.Value = "Actor"
            ddlFilter.Items.Add(ddlItem)

            ddlItem = New ListItem
            ddlItem.Text = "Description"
            ddlItem.Value = "Description"

            'Now that the ListItems are created, last step is to add them to the drop down list.
            ddlFilter.Items.Add(ddlItem)

        End If

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 07:41AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month