求asp.net 2.0可输入的Dropdownlist控件。
求asp.net 2.0可输入的Dropdownlist控件。
[解决办法]
http://www.a0923.com/AutoComplete/AutoComplete.aspx
[解决办法]
下面是代码,自己用vs2003编译成dll,放心可以在。net 2.0使用的。
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Text;
using System.Resources;
using System.Web;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Drawing;
namespace TopWin.WebControls
{
[
Designer(typeof(TopWin.WebControls.ComboBoxDesigner)),
ValidationProperty( "Text "),
]
public class ComboBox : System.Web.UI.WebControls.ListControl, IPostBackDataHandler, INamingContainer
{
/// <summary>
/// Creates a new instance of the ComboBox control.
/// </summary>
public ComboBox() : base() {}
#region Events
/// <summary>
/// The event which occurs when the <see cref= "Text "/> property is changed.
/// </summary>
public event EventHandler TextChanged;
/// <summary>
/// Raises the <see cref= "TextChanged "/> event.
/// </summary>
/// <param name= "e "> The data for the event. </param>
protected virtual void OnTextChanged( EventArgs e )
{
if ( TextChanged != null )
{
TextChanged( this, e );
}
}
#endregion
#region Implementation of IPostBackDataHandler
void IPostBackDataHandler.RaisePostDataChangedEvent()
{
OnSelectedIndexChanged(System.EventArgs.Empty);
}
bool IPostBackDataHandler.LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
// No need to check for the text portion changing. That is handled automagically
bool listIndexChanged = false;
if( TextIsInList )
{
ListItem selectedItem = this.Items.FindByText(text.Text);
Int32 selectedIndex = Items.IndexOf( selectedItem );
if ( this.SelectedIndex != selectedIndex )
{
listIndexChanged = true;
this.SelectedIndex = selectedIndex;
}
}
else
{
if ( this.SelectedIndex != -1 )
{
listIndexChanged = true;
this.SelectedIndex = -1;
}
}
isLoaded = true;
return listIndexChanged;
}
#endregion
#region New Properties
/// <summary>
/// Gets or sets the number of rows displayed in the dropdown portion of the <see cref= "ComboBox "/> control.
/// </summary>
/// <value>
/// The number of rows displayed in the <see cref= "ComboBox "/> control. The default value is 4.
/// </value>
[
Description( "Gets or sets the number of rows of the dropdown portion of the ComboBox control. "),
Category( "Appearance "),
DefaultValue(4),
Bindable(true),
]
public virtual Int32 Rows
{
get
{
object savedRows;
savedRows = this.ViewState[ "Rows "];
if (savedRows != null)
return (Int32) savedRows;
return 8;
}
set
{
if ( value < 1 )
{
throw new ArgumentOutOfRangeException();
}
this.ViewState[ "Rows "] = value;
}
}
/// <summary>
/// Gets or sets the text content of the text box portion of the <see cref= "ComboBox "/> control.
/// </summary>
[
Description( "Gets or sets the text content of the text box portion of the ComboBox control. "),
Category( "Appearance "),
Bindable(true),
DefaultValue( " ")
]
public virtual String Text
{
get
{
this.EnsureChildControls();
if ( text.Text == null )
{
return String.Empty;
}
return text.Text;
}
set
{
this.EnsureChildControls();
text.Text = value;
}
}
/// <summary>
/// Gets a boolean value indicating whether the string in the text portion of the <see cref= "ComboBox "/>
/// can be found in the text property of any of the ListItems in the Items collection.
/// </summary>
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public virtual bool TextIsInList
{
get
{
this.EnsureChildControls();
return ( Items.FindByText( text.Text ) != null );
}
}
/// <summary>
/// Gets a boolean value indicating whether an external script library should be used,
/// instead of the library being emitted as a whole.
/// </summary>
protected virtual bool UseReferenceLibrary
{
get
{
return ( ReferenceLibraryUrl != String.Empty );
}
}
/// <summary>
/// Queries the web.config file to get the external reference script library path, if available.
/// </summary>
protected virtual String ReferenceLibraryUrl
{
get
{
NameValueCollection config = ConfigurationSettings.GetConfig( "MetaBuilders.WebControls.ComboBox ") as NameValueCollection;
if( config != null )
{
return config[ "ReferenceLibraryUrl "];
}
return String.Empty;
}
}
#endregion