Technical Training
ASP.NET TrainingTable of Contents
ASP.NET Web Forms Controls
ASP.NET Hyperlink Controls
ASP.NET Button Controls
ASP.NET List ControlsASP.NET List Controls
ASP.NET Web Forms Controls
List Controls:
List controls provide the user with a number of options to choose from. A user has a choice to select a single option or list of options. The ListBox control provided by Asp.net controls collection. The listbox control has a collection property which is known as items. You can click on the property and populate the ListBox with the data and the value you desire. While populating the ListBox remember that the Text property of the ListBox is the text which will appear inside the it and the value is simple value. Usually we set the value to an integer which maps to some column in the database. Lets see how we can select a simple item in the ListBox control.
- private void ListBox2_SelectedIndexChanged(object sender, System.EventArgs e) {
- string selectedItemTextFromListBox = ListBox1.SelectedItem;
- // Returns the text
- string selectedItemValueFromListBox = ListBox1.SelectedValue;
- // returns the value
- }
The listbox exposes the property of SelectedItem and SelectedValue which can be used to find the selected item or selected value. You can also set the SelectionMode of the ListBox to multiple which allows the user to select multiple items with the ctrl key being pressed while selecting. Here is a small piece of code you can use to find out all the selected items in the listbox.
- private void ListBox2_SelectedIndexChanged(object sender, System.EventArgs e) {
- foreach(ListItem l in ListBox1.Items) {
- if(l.Selected) {
- selectedItems += l.Text;
- selectedValue += l.Value;
- }
- }
- }
The foreach loop will iterate the collection and if it finds the selected item it will assign to the string.
In the next tutorial we will see more advanced controls.
References:
www.msdn.microsoft.com
www.asp.net
ASP.NET Training
- ASP.NET with C# Training Launch
- ASP.NET with C# Training Course Outline
- Introduction to ASP.NET with C#
- ASP.NET Web Forms Controls
- ASP .NET: Validating User Input with C#
- Using Rich Server Controls with C#
- Accessing Data with C#
- ASP.NET Using the DataList and Repeater, Datagrid Controls
- Managing Data with ADO.NET DataSets and C#
- Creating and consuming XML Web Services with C#
- ASP .NET Migration and Interoperability
- Managing State with ASP.NET and C#
- Caching in ASP.NET
- Configuring and Deploying ASP.NET Applications
- Securing ASP.NET Applications with C#







