📄 duallist.cs
字号:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Resources;
using System.ComponentModel;
namespace MetaBuilders.WebControls {
/// <summary>
/// Provides the UI for the common requirement of two listboxes with items that move between them.
/// </summary>
/// <remarks>
/// <p>When DataBinding is used, the control will automaticly remove items from the left side if they exist on the right side. This ensures that double items can't be chosen.</p>
/// <p>
/// For browsers that support scripting, the movement will be completely clientside. There is also 100% serverside support, for any browsers with script disabled or nonexistant.
/// </p>
/// <p>By default, the clientscript used by the control is emited directly into the page.
/// In order to save bandwidth, it's possible to have the control to use a script reference instead,
/// but this requires the following handler to be added to the httpHandlers section of web.config.</p>
/// <code>
/// <httpHandlers>
/// <add verb="*"
/// path="MetaBuilders_WebControls_DynamicListBoxResourceHandler.axd"
/// type="MetaBuilders.WebControls.DynamicListBoxResourceHandler,MetaBuilders.WebControls.DynamicListBox"
/// validate="false"
/// />
/// </httpHandlers>
/// </code>
/// </remarks>
/// <example>
/// The following is a simple example that uses this control.
/// <code><![CDATA[
/// <%@ Register TagPrefix="mbdlb" Namespace="MetaBuilders.WebControls" Assembly="MetaBuilders.WebControls.DynamicListBox" %>
/// <script runat="server" language="c#" >
/// protected void DualList1_ItemsMoved( Object sender, EventArgs e ) {
/// DualResult.Text = "The Chosen Items Are:";
/// foreach( ListItem item in DualList1.RightBox.Items ) {
/// DualResult.Text += "<br>" + item.Value + "/" + item.Text;
/// }
/// }
/// </script>
/// <form runat="server">
/// <mbdlb:DualList runat="server" Id="DualList1" OnItemsMoved="DualList1_ItemsMoved" >
/// <LeftItems>
/// <asp:ListItem Value="1" Text="One" />
/// <asp:ListItem Value="2" Text="Two" />
/// <asp:ListItem Value="3" Text="Three" />
/// </LeftItems>
/// <RightItems>
/// <asp:ListItem Value="4" Text="Four" />
/// <asp:ListItem Value="5" Text="Five" />
/// <asp:ListItem Value="6" Text="Six" />
/// </RightItems>
/// </mbdlb:DualList>
/// <br><br><asp:Label runat="server" id="DualResult" />
/// <hr><asp:Button runat="server" text="Smack"/>
/// </form>
/// ]]></code>
/// </example>
[
DefaultProperty("ItemsName"),
DefaultEvent("ItemsMoved"),
PersistChildren(false),
ParseChildren(true),
]
public class DualList : System.Web.UI.WebControls.WebControl, INamingContainer {
#region Composite Control Pattern
/// <summary>
/// Overrides <see cref="Control.Controls"/> to implement the Composite Control Pattern
/// </summary>
public override ControlCollection Controls {
get {
this.EnsureChildControls();
return base.Controls;
}
}
/// <summary>
/// Overrides <see cref="Control.CreateChildControls"/> to implement the Composite Control Pattern
/// </summary>
protected override void CreateChildControls() {
this.Controls.Clear();
this.InitializeComponent();
}
#endregion
#region Events
/// <summary>
/// The event that fires when items have been moved.
/// </summary>
public event EventHandler ItemsMoved;
/// <summary>
/// Raises the <see cref="ItemsMoved"/> event.
/// </summary>
protected virtual void OnItemsMoved(EventArgs e) {
if ( this.ItemsMoved != null ) {
this.ItemsMoved(this,e);
}
}
#endregion
#region Properties
/// <summary>
/// Overrides <see cref="WebControl.TagKey"/>
/// </summary>
protected override HtmlTextWriterTag TagKey {
get {
return HtmlTextWriterTag.Table;
}
}
#region LeftBox
/// <summary>
/// Gets or sets the DataSource of the list on the left side of the control.
/// </summary>
[
Description("Gets or sets the DataSource of the list on the left side of the control."),
Category("Data"),
Bindable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public virtual Object LeftDataSource {
get {
this.EnsureChildControls();
return this.leftBox.DataSource;
}
set {
this.EnsureChildControls();
this.leftBox.DataSource = value;
}
}
/// <summary>
/// Gets or sets the DataMember of the list on the left side of the control.
/// </summary>
[
Description("Gets or sets the DataMember of the list on the left side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String LeftDataMember {
get {
this.EnsureChildControls();
return this.leftBox.DataMember;
}
set {
this.EnsureChildControls();
this.leftBox.DataMember = value;
}
}
/// <summary>
/// Gets or sets the DataTextField of the list on the left side of the control.
/// </summary>
[
Description("Gets or sets the DataTextField of the list on the left side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String LeftDataTextField {
get {
this.EnsureChildControls();
return this.leftBox.DataTextField;
}
set {
this.EnsureChildControls();
this.leftBox.DataTextField = value;
}
}
/// <summary>
/// Gets or sets the DataValueField of the list on the left side of the control.
/// </summary>
[
Description("Gets or sets the DataValueField of the list on the left side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String LeftDataValueField {
get {
this.EnsureChildControls();
return this.leftBox.DataValueField;
}
set {
this.EnsureChildControls();
this.leftBox.DataValueField = value;
}
}
/// <summary>
/// Gets or sets the DataTextFormatString of the list on the left side of the control.
/// </summary>
[
Description("Gets or sets the DataTextFormatString of the list on the left side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String LeftDataTextFormatString {
get {
this.EnsureChildControls();
return this.leftBox.DataTextFormatString;
}
set {
this.EnsureChildControls();
this.leftBox.DataTextFormatString = value;
}
}
/// <summary>
/// Gets the items in the list the left side of the control.
/// </summary>
[
Description("Gets the items in the list the left side of the control."),
DefaultValue(null),
MergableProperty(false),
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
]
public virtual ListItemCollection LeftItems {
get {
this.EnsureChildControls();
return this.leftBox.Items;
}
}
/// <summary>
/// Gets the <see cref="WebControl.ControlStyle"/> of the list on left side of the control.
/// </summary>
[
Description("Gets the ControlStyle of the list on left side of the control."),
Category("Appearance"),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
]
public virtual Style LeftListStyle {
get {
this.EnsureChildControls();
return this.leftBox.ControlStyle;
}
}
#endregion
#region RightBox
/// <summary>
/// Gets or sets the DataSource of the list on the right side of the control.
/// </summary>
[
Description("Gets or sets the DataSource of the list on the right side of the control."),
Category("Data"),
Bindable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public virtual Object RightDataSource {
get {
this.EnsureChildControls();
return this.rightBox.DataSource;
}
set {
this.EnsureChildControls();
this.rightBox.DataSource = value;
}
}
/// <summary>
/// Gets or sets the DataMember of the list on the right side of the control.
/// </summary>
[
Description("Gets or sets the DataMember of the list on the right side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String RightDataMember {
get {
this.EnsureChildControls();
return this.rightBox.DataMember;
}
set {
this.EnsureChildControls();
this.rightBox.DataMember = value;
}
}
/// <summary>
/// Gets or sets the DataTextField of the list on the right side of the control.
/// </summary>
[
Description("Gets or sets the DataTextField of the list on the right side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String RightDataTextField {
get {
this.EnsureChildControls();
return this.rightBox.DataTextField;
}
set {
this.EnsureChildControls();
this.rightBox.DataTextField = value;
}
}
/// <summary>
/// Gets or sets the DataValueField of the list on the right side of the control.
/// </summary>
[
Description("Gets or sets the DataValueField of the list on the right side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String RightDataValueField {
get {
this.EnsureChildControls();
return this.rightBox.DataValueField;
}
set {
this.EnsureChildControls();
this.rightBox.DataValueField = value;
}
}
/// <summary>
/// Gets or sets the DataTextFormatString of the list on the right side of the control.
/// </summary>
[
Description("Gets or sets the DataTextFormatString of the list on the right side of the control."),
Category("Data"),
DefaultValue(""),
]
public virtual String RightDataTextFormatString {
get {
this.EnsureChildControls();
return this.rightBox.DataTextFormatString;
}
set {
this.EnsureChildControls();
this.rightBox.DataTextFormatString = value;
}
}
/// <summary>
/// Gets the items in the list the right side of the control.
/// </summary>
[
Description("Gets the items in the list the right side of the control."),
DefaultValue(null),
MergableProperty(false),
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
]
public virtual ListItemCollection RightItems {
get {
this.EnsureChildControls();
return this.rightBox.Items;
}
}
/// <summary>
/// Gets the <see cref="WebControl.ControlStyle"/> of the list on right side of the control.
/// </summary>
[
Description("Gets the ControlStyle of the list on right side of the control."),
Category("Appearance"),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
]
public virtual Style RightListStyle {
get {
this.EnsureChildControls();
return this.rightBox.ControlStyle;
}
}
#endregion
/// <summary>
/// Gets or sets the number of rows visible in the lists of the control.
/// </summary>
[
Description("Gets or sets the number of rows visible in the lists of the control."),
Category("Appearance"),
DefaultValue(8),
]
public virtual Int32 ListRows {
get {
this.EnsureChildControls();
return this.leftBox.Rows;
}
set {
this.EnsureChildControls();
this.leftBox.Rows = value;
this.rightBox.Rows = value;
}
}
/// <summary>
/// Gets or sets the text displayed above the lists, the plural name of the items being chosen.
/// </summary>
[
Description("Gets or sets the text displayed above the lists, the plural name of the items being chosen."),
Category("Appearance"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -