日期:2014-05-20  浏览次数:20372 次

求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;