Chevy Mark Sunderland

Chevy Mark Sunderland

  • NA
  • 188
  • 167.3k

[C# net 4] AutoComplete TextBox

Apr 29 2013 4:16 PM
hi all, hope in your help.

I worked with this tutorial http://www.asp.net/ajaxlibrary/act_AutoComplete_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?


[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();
}
}

Answers (2)