Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2013, 04:17 PM
Authorized User
 
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default [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" />
 
Old May 4th, 2013, 05:40 PM
Authorized User
 
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default

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();
    }
 
Old August 13th, 2014, 02:45 AM
Registered User
 
Join Date: Aug 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A complete gridview auide....ASP.Net GridView Tutorial

Eldo





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.Net AJAX AutoComplete Extender help Djvarley ASP.NET 4 General Discussion 3 August 24th, 2011 04:39 AM
Help needed regarding autocomplete textbox in dot net 2.0 Yuvanya General .NET 0 July 8th, 2009 06:05 AM
autocomplete dropdownlistASP.NET 2.0 & VB.NET 2005 alexdcosta ASP.NET 2.0 Professional 10 May 11th, 2009 02:21 AM
autocomplete textbox like google nilsan ASP.NET 1.0 and 1.1 Basics 1 February 27th, 2007 07:36 AM
autocomplete textbox like google nilsan ASP.NET 1.0 and 1.1 Professional 0 February 27th, 2007 05:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.