Click here to Skip to main content
15,886,199 members
Articles / Web Development / HTML

AJAX AutoComplete/AutoSuggest TextBox

Rate me:
Please Sign up or sign in to vote.
4.86/5 (51 votes)
2 Oct 20074 min read 880.9K   7K   147  
An article on AJAX AutoSuggest control
using System;
using System.Text;
using System.Web;


namespace Anthem
{
	/// <summary>Data structure for menu items in suggestion div</summary>
	public class AutoSuggestMenuItem
	{
		private string _text;
		private string _value;
		private bool _isSelectable;
		private string _cssClass;
        private string _textBoxText;

		#region Class Properties
		
		public string Text
		{
			get	{return _text;}
			set	{_text=value;}
		}

		public string Value
		{
			get	{return _value;}
			set	{_value=value;}
		}

		
		public bool IsSelectable
		{
			get	{return _isSelectable;}
			set	{_isSelectable=value;}
		}

		public string CSSClass
		{
			get	{return _cssClass;}
			set	{_cssClass=value;}
		}

        public string TextBoxText
        {
            get { return _textBoxText; }
            set { _textBoxText = value; }
        }
		#endregion


		//Constructor
		public AutoSuggestMenuItem()
		{
			_cssClass="asbMenuItem";
			_isSelectable=true;
		}


		public string GenHtml(int nItemIndex, string sTextBoxID)
		{
			string sMenuItemValueID;
			string sFunc1;
			string sFunc2;
			
			string sHtml="";
			if (this.IsSelectable)
			{
				string sCtrlID=sTextBoxID + "_mi_" + nItemIndex;
				string sObj="asbGetObj('" + sTextBoxID + "')";

				sFunc1=sObj + ".OnMouseClick(" + nItemIndex + ")";
				sFunc2=sObj + ".OnMouseOver(" + nItemIndex  + ")";
				
				sHtml += "<div class=\"" + this.CSSClass + "\"" +
								" id=\"" + sCtrlID + "\"" +
								" name=\"" + sCtrlID + "\"" +
								" value=\"" + System.Web.HttpUtility.HtmlEncode(this.Value) + "\"" +
                                " textboxdisplay=\"" + System.Web.HttpUtility.HtmlEncode(this.TextBoxText) + "\"" +
								" onclick=\"" + sFunc1 + "\"" + 
								" onmouseover=\"" + sFunc2 + "\">" + this.Text + "</div>";
				sMenuItemValueID=sCtrlID + "_value";
				sHtml += "\n\r";
			}
			else
			{
				sHtml += "<div class=\"" + this.CSSClass + "\" style=\"cursor:auto\">" + this.Text + "</div>";
			}

			return sHtml;
		}
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Intelligent Coder
Canada Canada
I've been developing .NET enterprise applications since 2000.

I am originally from Rio de Janeiro and I am currently working at http://www.intelligentcoder.com in Ontario.

I also have my own startup where we offer client intake forms.

Comments and Discussions