SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    [C# net 4] AutoComplete TextBox

    hi all, hope in your help.

    I worked with this tutorial http://www.asp.net/ajaxlibrary/act_A...te_Simple.ashx

    I've problem because when in textbox selected one value I need update the gridview but the gridview not update, can you help me?

    Code:
        [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            OdbcConnection myConnectionString =
               new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnGCCom"].ConnectionString);
    
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
    
            OdbcCommand cmd = new OdbcCommand();
            cmd.Connection = myConnectionString;
            cmd.CommandType = CommandType.Text;
    
            cmd.CommandText = "SELECT ListNumber ";
            cmd.CommandText = cmd.CommandText + " FROM tbl_X ";
            cmd.CommandText = cmd.CommandText + " WHERE ListNumber LIKE CONCAT('%',?,'%') ";
            cmd.CommandText = cmd.CommandText + " GROUP BY ListNumber;";
            cmd.Parameters.AddWithValue("?", prefixText);
    
            try
            {
                myConnectionString.Open();
                cmd.ExecuteNonQuery();
                OdbcDataAdapter da = new OdbcDataAdapter(cmd);
                da.Fill(ds);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                myConnectionString.Close();
            }
    
            dt = ds.Tables[0];
            List<string> txtItems = new List<string>();
            String dbValues;
    
            foreach (DataRow row in dt.Rows)
            {
                dbValues = row["ListNumber"].ToString();
                dbValues = dbValues.ToLower();
                txtItems.Add(dbValues);
            }
    
            return txtItems.ToArray();
        }
    
    
    
    
        protected void decoderViewSource()
        {
            SQL = "SELECT * FROM ";
            SQL = SQL + "	tbl_X ";
            SQL = SQL + "WHERE ";
            SQL = SQL + "	1 ";
    
            if (ListNumber.Text != "")
            {
                SQL = SQL + " AND ListNumber ='" + ListNumber.Text + "' ";
            }
    
            Response.Write(SQL);
    
            try
            {
                OdbcDataAdapter adapter = new OdbcDataAdapter(SQL, myConnectionString);
                adapter.Fill(ds);
                DataView dv = new DataView();
                dv = ds.Tables[0].DefaultView;
                DecoderView.DataSource = dv;
                DecoderView.DataBind();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                myConnectionString.Close();
            }
        }
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                decoderViewSource();
            }
        }
    
    
    
                    <asp:TextBox ID="ListNumber" runat="server" AutoPostBack="true"></asp:TextBox>
                    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" TargetControlID="ListNumber"
                        runat="server" ServiceMethod="GetCompletionList" UseContextKey="True" />
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye

  2. #2
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Resolved:
    Code:
    <asp:TextBox ID="ListNumber" runat="server" AutoPostBack="true"
    OnTextChanged="textBox2_TextChanged"></asp:TextBox>
    
                    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" TargetControlID="ListNumber"
                        runat="server" ServiceMethod="GetCompletionList" UseContextKey="True" />
    
        protected void textBox2_TextChanged(object sender, EventArgs e)
        {
            DecoderView.DataBind();
            decoderViewSource();
        }
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •