Question

My ASPX Code:

<asp:TextBox ID="txtCollectionCode" runat="server" CssClass="txt" />
<asp:AutoCompleteExtender ID="AutoCompleteCollectionCode" runat="server" TargetControlID="txtCollectionCode" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="100" ServiceMethod="GetCollectionCode" />

Code Behind:

public static List<string>GetCollectionCode(string prefixText)
    {
        string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        SqlConnection conn = new SqlConnection(constr);

    SqlCommand cmd = new SqlCommand("Select Collection_Code From Collections_New WHERE Collection_Code LIKE @Collection_Code+'%'", conn);
    SqlDataAdapter adp = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    adp.Fill(dt);
    conn.Close();

    List<string> CollectionCodes = new List<string>();
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        CollectionCodes.Add(dt.Rows[i][1].ToString());
    }
    return CollectionCodes;
}

My Problem: This code works when I have to draw names. But from the same table when I try to draw the collection_codes (3001,3002,3003 for example) there is no autosuggestion.

Any help would be greatly appreciated! Thank you

Was it helpful?

Solution

I guess I figured it out.

public static ListGetCollectionCode(string prefixText) { string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); SqlConnection conn = new SqlConnection(constr);

    SqlCommand cmd = new SqlCommand("Select * FROM Collections_New WHERE Collection_Code LIKE '" + prefixText + "%'", conn);
    DataSet ds = new DataSet();
    SqlDataAdapter dta = new SqlDataAdapter(cmd);
    dta.Fill(ds);
    conn.Close();

    List<string> CollectionCodes = new List<string>();
      for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
      {
          CollectionCodes.Add(ds.Tables[0].Rows[i]["Collection_Code"].ToString());
      }
      return CollectionCodes;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top