Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
First of all I am new to C Sharp In my Search Project I am Searching with a Anthem AutoSuggest box, when a user enter the search word it AutoSuggest with the like values fetched from the Database its all going right but when I move my Mouse Over one of the Suggestions fetched the text entered by the user is been over-written by that text but I don’t want it to be happening I want the User to see the text entered by him also with the Suggestions if he wants from the suggestions he can select it (Like Google Search Application). Can any one Suggest me how to achieve this

My Code is,

C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class MultipleColumns : System.Web.UI.Page
{
#region Session Variables
private DataTable _dtProducts
{
    get { return (DataTable)Session["_dtProducts"]; }
    set { Session["_dtProducts"] = value; }
}
#endregion

protected void Page_Load(object sender, EventArgs e)
{

    if (!this.IsPostBack)
    {
        D_ddlanimal.Items.Insert(0, "--Select--");
        D_ddlanimal.SelectedIndex = 0;
        FillDataTable();
    }
}
protected void ClientMessaging(string msg)
{
    String script = String.Format("alert('{0}');", msg);
    Anthem.Manager.IncludePageScripts = true;
    Page.ClientScript.RegisterStartupScript(this.GetType(), "errMsg", script, true);
}

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    this.asbProduct.TextChanged += new Anthem.AutoSuggestBox.TextChangedEventHandler(asbProduct_TextChanged);
}


#region FillDataTable
/// <summary>
/// This method fills the datatable that is used in this example
/// On a real world application you usually would use a database
/// </summary>
private DataRow FillDataTable()
{
    using (SqlConnection obj_SqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString))
    {
        using (SqlCommand obj_Sqlcommand = new SqlCommand())
        {
            obj_Sqlcommand.CommandType = CommandType.StoredProcedure;
            obj_Sqlcommand.CommandText = "LRS_SP_CBFM_Sel";
            obj_Sqlcommand.Connection = obj_SqlConnection;
            obj_SqlConnection.Open();
            SqlDataAdapter da = new SqlDataAdapter(obj_Sqlcommand);

            DataSet ds = new DataSet();
            da.Fill(ds);
            ds.WriteXml(Server.MapPath("~/App_Data/Animalcode.xml"));
            ds.ReadXml(Server.MapPath("~/App_Data/Animalcode.xml"));
            _dtProducts = new DataTable();
            _dtProducts = ds.Tables[0];

         DataRow row = _dtProducts.NewRow();
        for (int i = 0; i < _dtProducts.Rows.Count;i++ )
       {
           row["pk_animalid"] = _dtProducts.Rows[i]["pk_animalid"].ToString();
           row["AnimalCode"] = _dtProducts.Rows[i]["AnimalCode"].ToString();
           row["ManualAnimalCode"] = _dtProducts.Rows[i]["ManualAnimalCode"].ToString();
       }
        return row;
      }

    }

}
#endregion

    /// <summary>
/// This event handler is used to fill the suggest list that appears as the user types
/// Usually you would query a database, but for the sake of simplicity we are querying an in-memory datatable
/// </summary>  
void asbProduct_TextChanged(object source, Anthem.AutoSuggestEventArgs e)
{
    //Creates a dataview of the session's datatable 
    DataView dv = new DataView(_dtProducts);
    //Filters the datatable based on the CurrentText property
    dv.RowFilter = string.Format("AnimalCode LIKE '%{0}%'", e.CurrentText);
    //Sets the dataview as the control's datasource             
    asbProduct.DataSource = dv;
    asbProduct.DataBind();
}
protected void adddet_Click(object sender, EventArgs e)
{

    if (asbProduct.Text == "" || asbProduct.Text == null)
    {
        ClientMessaging("Enter the Animal Code Number...");
    }
        D_ddlanimal.Items.Clear();
        D_ddlanimal.Items.Insert(0, "--Select--");
        D_ddlanimal.SelectedIndex = 0;
        D_ddlanimal.Items.Add(asbProduct.Text);
        D_ddlanimal.SelectedIndex = D_ddlanimal.SelectedIndex + 1;
        //DataRow dr = Filltbl();
        //D_ddlanimal.DataTextField = dr["AnimalCode"].ToString();
        //D_ddlanimal.DataValueField = dr["pk_animalid"].ToString();


}}
Posted

you can do it with ajax autocomplete extender......
 
Share this answer
 
Try google again.If you type something and get the auto suggesion,if you select auto suggesion then the value entered by you will be obviously ovewritten.It wont append the text with auto suggesion.

Further,if you type x,google suggest you xmen,xtreme etc, then if only x(entered by you) exist in the database,then it will be displayed as well in auto suggession,there is no need to append user entered value with auto suggested ones. And if anyway you managed to do that,it will ultimately give you zero results.

Regards.. :laugh:
 
Share this answer
 
I have no idea about Anthem !!!
I used jQuery
http://jqueryui.com/autocomplete/[^]
Another way is ajax toolkit autocomplete extender
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900