ASP.NET.in.a.Nutshell.Second.Edition [Electronic resources]

G. andrew Duthie; matthew Macdonald

نسخه متنی -صفحه : 873/ 726
نمايش فراداده

CheckBoxListdisposable

System.Web.UI.WebControls (system.web.dll)class

This class represents a list of checkboxes that can be selected in any combination. Though this class is generated out of individual checkboxes, it acts like an integrated list. For example, ASP.NET will add or remove checkbox items as needed when you bind it to a data source. You can use RepeatDirection to specify how checkboxes will be grouped together if RepeatColumns is greater than 1. For example, if you set RepeatDirection to RepeatDirection.Vertical, and RepeatColumns to 2, the first two list items will be displayed in the first columns, the next two will be displayed on the second column, and so on. If you set RepeatDirection to RepeatDirection.Horizontal, your list will still have the same number of rows and columns, but checkbox items will be filled first by column, and then by row.

Individual checkboxes are grouped together automatically in an HTML table, which you can fine-tune with the CellPadding and CellSpacing properties. Alternatively, you can set RepeatLayout to RepeatLayout.Flow to specify that an HTML table should not be used.

Most of the list-specific functionality, such as determining the selected item and reacting to a SelectedIndexChanged event, is provided by the ListControl class, which CheckBoxList inherits from. To determine what items are checked in a checkbox list, iterate through the Items collection and test the ListItem.Selected property of each item in the list.

public class 

CheckBoxList : ListControl, IRepeatInfoUser, System.Web.UI.INamingContainer, System.Web.UI.IPostBackDataHandler { // Public Constructors public

CheckBoxList ( ); // Public Instance Properties public virtual int

CellPadding {set; get; } public virtual int

CellSpacing {set; get; } public virtual int

RepeatColumns {set; get; } public virtual RepeatDirection

RepeatDirection {set; get; } public virtual RepeatLayout

RepeatLayout {set; get; } public virtual TextAlign

TextAlign {set; get; } // Protected Instance Methods protected override Style

CreateControlStyle ( ); // overrides WebControl protected override Control

FindControl (string

id , int

pathOffset ); // overrides System.Web.UI.Control protected override void

OnPreRender (EventArgs

e ); // overrides ListControl protected override void

Render (System.Web.UI.HtmlTextWriter

writer ); // overrides WebControl }

Hierarchy

System.Object System.Web.UI.Control(System.ComponentModel.IComponent, System.IDisposable, System.Web.UI.IParserAccessor, System.Web.UI.IDataBindingsAccessor) WebControl(System.Web.UI.IAttributeAccessor) ListControl CheckBoxList(IRepeatInfoUser, System.Web.UI.INamingContainer, System.Web.UI.IPostBackDataHandler)