show-notice
hide-notice

Saturday, 13 July 2013

ListBox Example in ASp.Net



Introduction


 

Here I will explain ListBox in ASP.NET.
Discription
The ListBox
control is used to create a single- or multi-selection drop-down list.Each selectable
item in a ListBox control is defined by a ListItem element! The ListControl control
covers all the base functions for list controls. Controls that inherits from this
control include the CheckBoxList, DropDownList, ListBox, and RadioButtonList controls.








<%@
page language="C#"
%>




<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




<script runat="server"> 



       
protected void ListBox1_SelectedIndexChanged(object sender, System.EventArgs e) 



       



           
Label1.Text = "Your Favorite Color: " + ListBox1.SelectedItem.Text; 




       



</script>




<html
xmlns
="http://www.w3.org/1999/xhtml">


<head
id
="Head1" runat="server">


   
<title>listbox</title>


</head>


<body>


   
<form
id="form1" runat="server">


   
<div>


       
<h2 style="color:
Maroon">


           
ListBox: OnSelectedIndexChanged</h2>


       
<asp:label
id
="Label1" runat="server" font-bold="true" forecolor="SeaGreen" font-size="Large"> 




           
</asp:label>


       
<br />


       
<br />


       
<asp:label
id
="Label2" runat="server" font-bold="true" forecolor="DarkCyan" text="Color List"> 




           
</asp:label>


       
<br />


       
<asp:listbox
id
="ListBox1" runat="server" autopostback="true" onselectedindexchanged="ListBox1_SelectedIndexChanged"


           
backcolor="DarkCyan"
forecolor="AliceBlue"> 



                
<asp:ListItem>LawnGreen</asp:ListItem> 



                
<asp:ListItem>LightSalmon</asp:ListItem> 



                
<asp:ListItem>MediumBlue</asp:ListItem> 



                
<asp:ListItem>MediumOrchid</asp:ListItem> 



                
<asp:ListItem>Lavender</asp:ListItem> 



           
</asp:listbox>


   
</div>


   
</form>


</body>


</html>
 

SHARE THIS POST   

0 comments :

Post a Comment

Design by Gohilinfotech | www.gohilinfotech.blogspot.com