Click here to Skip to main content
15,881,173 members
Articles / Web Development / ASP.NET

Adding 'Google Suggest' functionality to an ASP.NET application

Rate me:
Please Sign up or sign in to vote.
4.76/5 (39 votes)
1 Dec 20055 min read 198.7K   4.4K   121  
Shows how to add 'Google Suggest' functionality to an ASP.NET application.
using System;
using System.Text;
using System.Web;


namespace ASB
{
	/// <summary>Data structure for menu items in suggestion div</summary>
	public class ASBMenuItem
	{
		private string msLabel;
		private string msValue;
		private bool mbIsSelectable;
		private string msCSSClass;

		#region Class Properties
		
		public string Label
		{
			get	{return msLabel;}
			set	{msLabel=value;}
		}

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

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

		public string CSSClass
		{
			get	{return msCSSClass;}
			set	{msCSSClass=value;}
		}
		#endregion


		//Constructor
		public ASBMenuItem()
		{
			msCSSClass="asbMenuItem";
			mbIsSelectable=true;
		}



		public string GenHtml(int nItemIndex, string sTextBoxID, string sDivID)
		{
			string sCtrlID;
			string sMenuItemValueID;
			string sFunc1;
			string sFunc2;
			
			string sHtml="";
			if (this.IsSelectable)
			{
				sCtrlID=sTextBoxID + "_mi_" + nItemIndex;
				sFunc1="asbOnMouseClick(" + nItemIndex + ", \"" + sTextBoxID + "\", \"" + sDivID + "\")";
				sFunc2="asbOnMouseOver(" + nItemIndex + ", \"" + sTextBoxID + "\")";
				
				sHtml += "<div class=\"" + this.CSSClass + "\" id=\"" + sCtrlID + "\" name=\"" + sCtrlID + "\" onclick='" + sFunc1 + "' + onmouseover='" + sFunc2 + "'>" + this.Label + "</div>";

				//Add hidden field to store the value of current item
				sMenuItemValueID=sCtrlID + "_value";
				sHtml += "\n\r";
				sHtml += "<input type=\"hidden\" id=\"" + sMenuItemValueID + "\" name=\"" + sMenuItemValueID + "\" value=\"" + System.Web.HttpUtility.HtmlEncode(this.Value) + "\">";
			}
			else
			{
				sHtml += "<div class=\"" + this.CSSClass + "\" style=\"cursor:auto\">" + this.Label + "</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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions