List Controls in ASP.NET 2.0
All the list controls inherit from the System.Web.UI.WebControls.ListControl class. Following are the ListControl Class Properties: 1. AutoPostBack: If AutoPostBack is true, the form is automatically posted back when the user changes the current selection.
2. DataSource: Specify the data source for the items.
3. DataMember: The DataMember property is used to identify the table user want to use.
4. DataTextField: Indicates the field from data source to use for option text.
5. DataValueField: Indicates the field from data source to use for option Value.
6. DataTextFormatString: Gets or sets the formatting string used to control how data bound to the list control is displayed.
7. Items: Returns a collection of ListItem items.
8. SelectedIndex: Returns or sets the index of the selected item.
9. SelectedItem: Returns a ListItem that represent the currently selected Item List Controls:
- BulletedList: BulletedList controls display list of items with a variety of bullet styles. User can also use this control to create a list of hyperlinks.BulletStyle property can be used to decide what type of style is needed. It can be Numbered (1, 2, 3…), LowerAlpha (a, b, c…) and UpperAlpha (A, B, C…), LowerRoman (i, ii, iii…) and UpperRoman (I, II, III…), and the bullet symbols Disc, Circle, Square.
- CheckBoxList: Represents a list of check boxes. Each list item in a CheckBoxList represents an individual check box.
- DropDownList: Allows the user to select a single item from a drop-down list.
- ListBox: Displays a list of items from which user can make a selection.
- RadioButtonList: The items are rendered as radio buttons.
Code:ListControl.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
ArrayList aryColor = new ArrayList();
if (!Page.IsPostBack)
{
aryColor.Add(“Red”);
aryColor.Add(“Black”);
aryColor.Add(“White”);
aryColor.Add(“Blue”);
//CheckBoxList
ChklColor.DataSource = aryColor;
ChklColor.DataBind();
//DropDownList
DdlColor.DataSource = aryColor;
DdlColor.DataBind();
//ListBox
LbColor.DataSource = aryColor;
LbColor.DataBind();
//RadioButtonList
RblColor.DataSource = aryColor;
RblColor.DataBind();
//BulletedList
BlColor.DataSource = aryColor;
BlColor.DataBind();
}
}
Code:ListControl.aspx
<form id=”form1″ runat=”server”>
<asp:CheckBoxList ID=”ChklColor” runat=”server”>
</asp:CheckBoxList> <br />
<asp:DropDownList ID=”DdlColor” runat=”server”>
</asp:DropDownList> <br />
<asp:ListBox ID=”LbColor” runat=”server”>
</asp:ListBox> <br />
<asp:RadioButtonList ID=”RblColor” runat=”server”>
</asp:RadioButtonList> <br />
<asp:BulletedList ID=”BlColor” runat=”server” BulletStyle=”Circle”></asp:BulletedList> <br />
<!– Hyperlink BulletedList –>
<asp:BulletedList ID=”BlHyperlink” DisplayMode=”HyperLink” runat=”server”> <asp:ListItem Value=”http://www.google.com”>GOOGLE</asp:ListItem>
<asp:ListItem Value=”http://www.asp.net”>ASP.NET</asp:ListItem>
<asp:ListItem Value=”http://msdn.microsoft.com”>MSDN</asp:ListItem>
</asp:BulletedList>
</form>
- Harpreet virk