本文介绍了自动完成扩展程序不列出记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有自动完成的扩展程序来列出名称.但是它不会列出值.
我不知道出什么问题了.

谁能帮我解决这个问题?

这是我的网络方法代码..

[WebMethod]
    public string[] getname(string prefixText)
    {
        DataSet dtst = new DataSet();

        SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["con"]);

        string strSql = "SELECT UserName FROM user_det WHERE UserName LIKE ''" + prefixText + "%'' ";

        SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);

        sqlCon.Open();

        SqlDataAdapter sqlAdpt = new SqlDataAdapter();

        sqlAdpt.SelectCommand = sqlComd;

        sqlAdpt.Fill(dtst);

        string[] cntName = new string[dtst.Tables[0].Rows.Count];

        int i = 0;

        try
        {

            foreach (DataRow rdr in dtst.Tables[0].Rows)
            {

                cntName.SetValue(rdr["UserName"].ToString(), i);

                i++;

            }

        }

        catch { }

        finally
        {

            sqlCon.Close();

        }

        return cntName;
    }


这是我的html代码

<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:TextBox ID="txtname" runat="server" OnTextChanged="txtname_TextChanged" AutoPostBack="True"> <asp:ScriptManager ID="ScriptManager1"
            runat="server">
        
        <ajax:AutoCompleteExtender ID="AutoCompleteExtender1"  runat="server" TargetControlID="txtname" ServicePath="WebService.asmx" ServiceMethod="getname" MinimumPrefixLength="1" EnableCaching="true">
    </div>
    </form>
</body>
</html>
解决方案


Hi
I have auto-complete extender to list names.but it will not list the values.
I dont know what is the issue..

Can anyone help me to solve this?

here is my web method code..

[WebMethod]
    public string[] getname(string prefixText)
    {
        DataSet dtst = new DataSet();

        SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["con"]);

        string strSql = "SELECT UserName FROM user_det WHERE UserName LIKE ''" + prefixText + "%'' ";

        SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);

        sqlCon.Open();

        SqlDataAdapter sqlAdpt = new SqlDataAdapter();

        sqlAdpt.SelectCommand = sqlComd;

        sqlAdpt.Fill(dtst);

        string[] cntName = new string[dtst.Tables[0].Rows.Count];

        int i = 0;

        try
        {

            foreach (DataRow rdr in dtst.Tables[0].Rows)
            {

                cntName.SetValue(rdr["UserName"].ToString(), i);

                i++;

            }

        }

        catch { }

        finally
        {

            sqlCon.Close();

        }

        return cntName;
    }


This is my html code

<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:TextBox ID="txtname" runat="server" OnTextChanged="txtname_TextChanged" AutoPostBack="True"> <asp:ScriptManager ID="ScriptManager1"
            runat="server">
        
        <ajax:AutoCompleteExtender ID="AutoCompleteExtender1"  runat="server" TargetControlID="txtname" ServicePath="WebService.asmx" ServiceMethod="getname" MinimumPrefixLength="1" EnableCaching="true">
    </div>
    </form>
</body>
</html>
解决方案



这篇关于自动完成扩展程序不列出记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 16:59