//Style
<style type="text/css">
.AutoExtender
{
font-family: Verdana, Helvetica, sans-serif;
font-size: 1.0em;
font-weight: normal;
border: solid 1px #95BF4E;
line-height: 20px;
padding: 10px;
background-color: White;
margin-left: 7px;
z-index: 100000;
overflow-y: scroll;
}
.AutoExtenderList
{
border-bottom: dotted 1px #95BF4E;
cursor: pointer;
color: Maroon;
}
.AutoExtenderHighlight
{
color: White;
background-color: #95BF4E;
cursor: pointer;
}
#divwidth
{
width: 160px !important;
height: 170px;
}
#divwidth div
{
width: 150px !important;
}
.watermarkfoodname
{
background-color: #F0F8FF;
color: #808080;
}
</style>
//Code on aspx page
<div id="divwidth">
</div>
<asp:TextBox ID="txtAddMyFoodName" runat="server" Width="140px" Height="22px" onkeyup="clearUnit();"
onblur="showUnit()"></asp:TextBox>
<%--<input type="hidden" runat="server" id="hdnProductId" />--%>
<ajaxToolkit:AutoCompleteExtender BehaviorID="bhvrSearch" runat="server" ID="AutoCompleteExtender1"
TargetControlID="txtAddMyFoodName" ServiceMethod="GetFoodompletionList" UseContextKey="true"
MinimumPrefixLength="1" CompletionInterval="1" ContextKey="0" EnableCaching="true"
CompletionListElementID="divwidth" CompletionListCssClass="AutoExtender" CompletionListItemCssClass="AutoExtenderList"
CompletionListHighlightedItemCssClass="AutoExtenderHighlight" OnClientItemSelected="FillCurrentStock" />
<ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server" TargetControlID="txtAddMyFoodName"
WatermarkText="Type Food Name Here" WatermarkCssClass="watermarkfoodname" />
//Code on Code behind File
#region GetCodeCompletionList
/// <summary>
/// This function is calling by product list control
/// </summary>
/// <creted by>Harish Kumar Chandna</creted by>
/// <creation date>17 AUGUST 2011</creation date>
/// <param name="prefixText"></param>
/// <param name="count"></param>
/// <param name="contextKey"></param>
/// <returns></returns>
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetFoodompletionList(string prefixText, int count, string contextKey)
{
try
{
List<String> suggestions = new List<string>();
DataSet ds = new DataSet();
//Fetch the products
DPService.DiabetesPilotServiceClient objService = new DPService.DiabetesPilotServiceClient();
ds = objService.FoodSearch(prefixText, 0);
//Traverse the entire products in list
foreach (DataRow drow in ds.Tables[0].Rows)
{
string html = drow["Food_Name"].ToString();
string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(drow["Food_Name"].ToString(), html);
suggestions.Add(item);
}
return suggestions.ToArray();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
<style type="text/css">
.AutoExtender
{
font-family: Verdana, Helvetica, sans-serif;
font-size: 1.0em;
font-weight: normal;
border: solid 1px #95BF4E;
line-height: 20px;
padding: 10px;
background-color: White;
margin-left: 7px;
z-index: 100000;
overflow-y: scroll;
}
.AutoExtenderList
{
border-bottom: dotted 1px #95BF4E;
cursor: pointer;
color: Maroon;
}
.AutoExtenderHighlight
{
color: White;
background-color: #95BF4E;
cursor: pointer;
}
#divwidth
{
width: 160px !important;
height: 170px;
}
#divwidth div
{
width: 150px !important;
}
.watermarkfoodname
{
background-color: #F0F8FF;
color: #808080;
}
</style>
//Code on aspx page
<div id="divwidth">
</div>
<asp:TextBox ID="txtAddMyFoodName" runat="server" Width="140px" Height="22px" onkeyup="clearUnit();"
onblur="showUnit()"></asp:TextBox>
<%--<input type="hidden" runat="server" id="hdnProductId" />--%>
<ajaxToolkit:AutoCompleteExtender BehaviorID="bhvrSearch" runat="server" ID="AutoCompleteExtender1"
TargetControlID="txtAddMyFoodName" ServiceMethod="GetFoodompletionList" UseContextKey="true"
MinimumPrefixLength="1" CompletionInterval="1" ContextKey="0" EnableCaching="true"
CompletionListElementID="divwidth" CompletionListCssClass="AutoExtender" CompletionListItemCssClass="AutoExtenderList"
CompletionListHighlightedItemCssClass="AutoExtenderHighlight" OnClientItemSelected="FillCurrentStock" />
<ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server" TargetControlID="txtAddMyFoodName"
WatermarkText="Type Food Name Here" WatermarkCssClass="watermarkfoodname" />
//Code on Code behind File
#region GetCodeCompletionList
/// <summary>
/// This function is calling by product list control
/// </summary>
/// <creted by>Harish Kumar Chandna</creted by>
/// <creation date>17 AUGUST 2011</creation date>
/// <param name="prefixText"></param>
/// <param name="count"></param>
/// <param name="contextKey"></param>
/// <returns></returns>
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetFoodompletionList(string prefixText, int count, string contextKey)
{
try
{
List<String> suggestions = new List<string>();
DataSet ds = new DataSet();
//Fetch the products
DPService.DiabetesPilotServiceClient objService = new DPService.DiabetesPilotServiceClient();
ds = objService.FoodSearch(prefixText, 0);
//Traverse the entire products in list
foreach (DataRow drow in ds.Tables[0].Rows)
{
string html = drow["Food_Name"].ToString();
string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(drow["Food_Name"].ToString(), html);
suggestions.Add(item);
}
return suggestions.ToArray();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
5:07 AM |
Category: |
1 comments
Comments (1)
this is the ajax autocomlete extender tool of ajax