Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0 search
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,
 
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 25-Jun-13 19:11pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 | :laugh:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

you can do it with ajax autocomplete extender......
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100