62,041
社区成员
发帖
与我相关
我的任务
分享
/*WebService*/
[WebMethod]
public DataSet GetInfoByName()
{
string name = HttpContext.Current.Request["rname"];
if (name.Length == 0)
name = "xxxx";
string strCmd = "select top 10 badge,name,c_name,comp_code,dept_code from employee where status=3 and (name like '" + name + "%' or c_name like N'" + name + "%')";;
string strConnection = ConfigurationManager.AppSettings["AAA_ASMUser"].Trim();
SqlDataAdapter da = new SqlDataAdapter(strCmd, strConnection);
da.SelectCommand.CommandTimeout = 240;
DataSet ds = new DataSet();
da.Fill(ds,"test");
da.Dispose();
//ds.WriteXml(Server.MapPath("\\Ecmsystem\\test\\") + "a.xml");
return ds;
}
/*示例:jquery文本框錄入智能感知*/
<script type="text/javascript" >
$(function(){
$('#<%= TextBox3.ClientID %>').keyup(function()
{
$.ajax({
url: 'WebService.asmx/GetInfoByName',
type: 'POST',
dataType:"xml",
data:{'rname':$(this).val()},
cache:false,
success: function(res)
{
var rdiv=$('#resultDiv');
rdiv.html('');
var tb="<table style='color:brown;font-size:12px;width:100%;'>"
$(res).find('test').each(function() { tb+="<tr><td>"+$(this).text()+"</td></tr>";})
tb+="</table>";
rdiv.html(tb);
rdiv.fadeIn();
rdiv.offset({ top: 100, left: 300 });
rdiv.find('td')
.click(function() { $('#<%= TextBox3.ClientID %>').val($(this).text()); rdiv.fadeOut(); })
.each(function(){ $(this).css({"cursor":"hand"}); });
rdiv.find('tr').hover(function(){$(this).css("background-Color","honeydew");},function(){$(this).css("background-Color","");});
if(rdiv.text()=="")
{
rdiv.fadeOut();
}
},
error: function(x, e)
{
alert(x.responseText);
}
});
});
});
</script>
<asp:TextBox ID="TextBox3" runat="server" Width="300px"></asp:TextBox>
<div id="resultDiv" style="border:double 2px blue; width:380px;display:none; height:100px; overflow:auto;"></div