ARTICLE

DropDownList control in ASP.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET November 16, 2010
In this article we will learn how to use DropDownList control in ASP. NET.
 
Reader Level:

HTML clipboard

In this article we will learn how to use DropDownList control in ASP. NET.

DropDownList control:

-DropDownList Allows to select only one item from many items.
-Use Items collection to add the items.
-Each item is an object of ListItem class ListItem(string text, string value).

Properties:

Items - The collection of items in the list.

ID - Programmatic name of the control.

AutoPostBack - Automatically postback to the server after selection is changed.

AccessKey - keyboard shortcut used by the control.

DropDownList event:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged

End Sub

For example:

Drag a DropDownList, Button and TextBox control on the form. when we select the items in the DropDownList and click on the button its should be display on the Textbox control.

The form looks like this:

dd1.gif

Figure 1.

HTML clipboard

Now double click on the form and add the below code.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

   If Not IsPostBack Then

            For i As Integer = 1950 To DateTime.Now.Year

                DropDownList1.Items.Add(New ListItem(i.ToString()))

            Next

        End If

    End Sub

 

Use Page.IsPostBack property to check the post backs.

 

Now double click on the button control and add the following code.

 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

 

        TextBox1.Text = DropDownList1.SelectedItem.Text.ToString()

 

    End Sub

 

Now save and run the application And click the DropDownList than DropDownList items will be display.

 

dd2.gif 

Figure 2.

HTML clipboar

 

Now select the items from the DropDownList then click on the button the selected items will be display on the TextBox.


dd3.gif 

Figure 3.

Login to add your contents and source code to this article
share this article :
post comment
 

asp.net making a site site name customer menagement ok so this site in login page but login deffrent -2 department login exampeal customer ,manager,empploy etc ok so i use dropdown list but nothing login page

Posted by titu kumar Apr 09, 2011
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Diagram
Become a Sponsor