已有57人关注
异步查找数据
发表在C#图书答疑 2011-05-05
是否精华
版块置顶:
怎么在当前页面输入名字,然后从另一个页面返回与之名字匹配的提示:
响应的页面程式
 protected void Page_Load(object sender, EventArgs e)
        {            
                     string[] a = new string[30];
                         a[0] ="Anna";
                        a[1] ="Brittany";
                        a[2] ="Cinderella";
                        a[3] ="Diana";
                        a[4] ="Eva";
                        a[5] ="Fiona";
                        a[6] ="Gunda";
                        a[7] ="Hege";
                        a[8] ="Inga";
                        a[9] ="Johanna";
                        a[10] ="Kitty";
                        a[11] ="Linda";
                        a[12] ="Nina";
                        a[13] ="Ophelia";
                        a[14] ="Petunia";
                        a[15] ="Amanda";
                        a[16] ="Raquel";
                        a[17] ="Cindy";
                        a[18] ="Doris";
                        a[19] ="Eve";
                        a[20] ="Evita";
                        a[21] ="Sunniva";
                        a[22] ="Tove";
                        a[23] ="Unni";
                        a[24] ="Violet";
                        a[25] ="Liza";
                        a[26] ="Elizabeth";
                        a[27] ="Ellen";
                        a[28] ="Wenche";
                        a[29] = "Vicky";
   string st = Request.QueryString["q"].ToString().ToUpper();
                        if (st.Length > 0)
                        {
                            string hint = "";

                            for (int i = 0; i < 30;i++ )
                            //  foreach (string s in a)
                            {
                            
                                if (st == a[i].ToString().Substring(0,st.Length).ToUpper())                               
          //problem!
                                {
                                    if (hint == "")
                                    {
                                        hint = a[i];
                                    }
                                    else
                                    {
                                        hint = hint + "," + a[i];
                                    }
                                }
                                //Response.Write(a[i]);
                                //  Response.Write("<br/>");
                            }
                            if (hint == "")
                            { Response.Write("no suggestion"); }
                            else
                                Response.Write(hint);
输入节目代码:

  <script type="text/javascript">
function showHint(str)
{
var xmlhttp;
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","/reptxt.aspx?q="+str,true);
xmlhttp.send();
}
</script>

</head>
<body>
<h3>请在下面的输入框中键入字母(A - Z):</h3>
<form action=""> 
姓氏:<input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>建议:<span id="txtHint"></span></p> 

分享到:
精彩评论 1
东方_mrkj
学分:0 LV1
2011-05-05
沙发
读者你好:
     请把问题发到ASP.NET论坛上。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照