close

***ASP***

 <td class="qry-title" nowrap="nowrap">
           交易行<br />
           <asp:TextBox ID="txt_Branch" runat="server" CssClass="input_textbox" MaxLength="8" Width="100px"></asp:TextBox>
           <ajaxToolkit:AutoCompleteExtender ID="txt_Branch_AutoCompleteExtender" runat="server"
                     CompletionInterval="750" DelimiterCharacters="" Enabled="True" MinimumPrefixLength="1"
                    
ServiceMethod="GetBranchList" ServicePath="" TargetControlID="txt_Branch" UseContextKey="True"
                    CompletionSetCount="15">
           </ajaxToolkit:AutoCompleteExtender>

 </td>

 

***ASP.CS***

 [System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethod()]
    public static string[] GetBranchList(string prefixText, int count, string contextKey)
    {
        List<string> result = new List<string>();
        try
        {
            prefixText = prefixText.ToUpper();
            SqlConnection con1 = new SqlConnection(TMConnStr);
            SqlCommand cmd1 = con1.CreateCommand();
            cmd1.CommandType = CommandType.Text;
            con1.Open();
            cmd1.CommandText = string.Format(
                     @"SELECT DISTINCT TOP {0} branchid, name
                          FROM dbo.branch
                          WHERE (Left(branchid,3) LIKE '[0-9][0-9][0-9]') AND (Left(name,1) NOT LIKE '[a-zA-Z]')
                                        AND (branchid + ' ' + name LIKE '%{1}%')
                          ORDER BY 1", count, prefixText);
            SqlDataReader sdr1 = cmd1.ExecuteReader();
            if (sdr1.HasRows)
            {
                while (sdr1.Read())
                    result.Add(Convert.ToString(sdr1[1]).Trim());
            }
            sdr1.Dispose();
            cmd1.Dispose();
            con1.Dispose();
        }
        catch (Exception ex)
        {
        }
        return result.ToArray();
    }

***畫面***

自動下拉.png

 

 

arrow
arrow
    全站熱搜

    可樂果公主 發表在 痞客邦 留言(0) 人氣()