二、ashx后台
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request.QueryString["q"] != null)
{
string key = context.Request.QueryString["q"];
if (key.Trim().Length >= 8)//大于等于8位,才去查数据库。这是为了缓解数据库查询的压力,只当输入了8位以上身份证以后才进行数据库检索。
{
string keyValues = GetKeyValues(key);
context.Response.Write(keyValues);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
public static string GetKeyValues(string key)
{
BLL bll = new BLL();
DataTable dt = bll.GetPersons(key).Tables[0];//通过关键字k(k是前台页面输入的身份证号码)到后台去查询人员信息并返回一个结果集
StringBuilder sb = new StringBuilder();
foreach (DataRow dr in dt.Rows)
{
sb.Append(dr["result"].ToString() + "n");
}
return sb.ToString().Trim();
}
如上代码即可实现输入身份证号时自动检索数据库并给出相关信息,当选择某条数据的时候,自动给文本框赋值,减少了人工的输入。
以上就是本文的全部内容,希望对大家的学习有所帮助。








