您现在的位置是:网站首页> 编程资料编程资料
.Net 文本框实现内容提示的实例代码(仿Google、Baidu)_实用技巧_
2023-05-24
357人已围观
简介 .Net 文本框实现内容提示的实例代码(仿Google、Baidu)_实用技巧_
1.Demo下载:
2.创建数据库、表(我用的sqlserver2008数据库)
CREATE TABLE Ceshi
(
id VARCHAR(50) PRIMARY KEY NOT NULL,
cname VARCHAR(30)
)
GO
INSERT INTO Ceshi
SELECT NEWID(),'jack1' UNION
SELECT NEWID(),'jack2' UNION
SELECT NEWID(),'jack3' UNION
SELECT NEWID(),'jack4' UNION
SELECT NEWID(),'jack5' UNION
SELECT NEWID(),'peter1' UNION
SELECT NEWID(),'peter2' UNION
SELECT NEWID(),'peter3' UNION
SELECT NEWID(),'peter4' UNION
SELECT NEWID(),'peter5'
go
3.创建自定义函数
create function [dbo].[f_GetPy](@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert into @t(chr,letter)
select '吖 ', 'A ' union all select '八 ', 'B ' union all
select '嚓 ', 'C ' union all select '咑 ', 'D ' union all
select '妸 ', 'E ' union all select '发 ', 'F ' union all
select '旮 ', 'G ' union all select '铪 ', 'H ' union all
select '丌 ', 'J ' union all select '咔 ', 'K ' union all
select '垃 ', 'L ' union all select '嘸 ', 'M ' union all
select '拏 ', 'N ' union all select '噢 ', 'O ' union all
select '妑 ', 'P ' union all select '七 ', 'Q ' union all
select '呥 ', 'R ' union all select '仨 ', 'S ' union all
select '他 ', 'T ' union all select '屲 ', 'W ' union all
select '夕 ', 'X ' union all select '丫 ', 'Y ' union all
select '帀 ', 'Z '
select @strlen=len(@str),@re= ' '
while @strlen> 0
begin
select top 1 @re=letter+@re,@strlen=@strlen-1
from @t a where chr <=substring(@str,@strlen,1)
order by chr desc
if @@rowcount=0
select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1
end
return(@re)
end
GO
4.asp.net前台页面(需要添加2个引用:AjaxControlToolkit.dll,AutoCompleteExtra.dll)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextBoxAuto.aspx.cs" Inherits="WebApplication1.TextBoxAuto" %>
<%@ Register Assembly="AutoCompleteExtra" Namespace="AutoCompleteExtra" TagPrefix="cc1" %>
5.后台页面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oceansoft.Net.Bll;
namespace WebApplication1
{
public partial class TextBoxAuto : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[][] GetCompanyNameList(string prefixText, int count, string contextKey)
{
//获取自动完成的选项数据
List
List
List
CeshiManage ceshimanage = new CeshiManage();
ceshimanage.GetTopUserName(count, prefixText.ToUpper(), out idList, out nameList);
for (int i = 0; i < nameList.Count; i++)
{
string[] Respuesta = new string[2];
Respuesta[0] = nameList[i];
Respuesta[1] = idList[i];
list.Add(Respuesta);
}
return list.ToArray();
}
}
}
6.后台页面用到的方法(管理类)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Oceansoft.Net.Bll;
using SubSonic;
using System.Transactions;
using System.Data;
using Oceansoft.Net.Dal;
namespace Oceansoft.Net.Bll
{
///
/// :ceshi
/// :jibp
/// :2014-2-27 15:52:15
///
public class CeshiManage
{
private SqlQuery m_sqlquery = Oceansoft.Net.Dal.DB.Select().From(Ceshi.Schema);
///
/// Ceshi查询器
///
public SqlQuery CeshiSelecter
{
get { return m_sqlquery; }
set { m_sqlquery = value; }
}
///
/// 构造函数,设置查询器
///
public CeshiManage()
{
m_sqlquery = m_sqlquery.Where("id").IsNotEqualTo("");
}
#region Ceshi管理
///
/// 获取ceshi列表
///
///
public List
{
return CeshiSelecter.ExecuteTypedList
}
///
/// 获取ceshi列表,同时分页操作
///
///
public List
{
RecordCount = m_sqlquery.GetRecordCount();
return CeshiSelecter
.Paged(currentPage, pageSize)
.ExecuteTypedList
}
///
/// 新增 ceshi
///
///
///
///
public bool AddCeshi(Ceshi beAddMode, out string sErr)
{
sErr = "";
bool bRet = true;
try
{
using (TransactionScope sc = new TransactionScope())
{
//此处写代码
//流水编号的生成
//GenerateNo No = new GenerateNo();
//No.TableName = "Ceshi"; //表名
//No.NoName = "XXX"; //流水号前字母
//No.ColName = "CC_Number"; //编号字段
//No.CreateTime = "CC_CreateTime"; //日期字段
//string BillNo = "";
//Customer_Comp.CC_Number = No.AutoGenerateNo();
beAddMode.IsNew = true;
beAddMode.Save();
//LogHelper.WriteLog(logType.新增 , logModule.Deptrelation,"ceshi新增成功("+beAddMode.GetPrimaryKeyValue().ToString()
//+")!");
//如果生成扩展类请使用add方法方法
sc.Complete();
}
}
catch (Exception ex)
{
sErr = "ceshi新增不成功!";
return false;
}
sErr = "ceshi新增成功!";
return bRet;
}
///
/// 修改 ceshi
///
///
///
///
public bool UpdataCeshi(Ceshi beUpdataMode, out string sErr)
{
sErr = "";
bool bRet = true;
try
{
using (TransactionScope sc = new TransactionScope())
{
//如果生成扩展类请使用Update()方法方法
beUpdataMode.IsNew = false;
beUpdataMode.Save();
相关内容
- 在aspx页面引用html页的写法_实用技巧_
- DataSet、DataTable、DataRow区别详解_实用技巧_
- asp.net中C#获取字符串中汉字的个数的具体实现方法_实用技巧_
- asp.net 备份和恢复数据库的方法示例_实用技巧_
- asp.net操作xml增删改示例分享_实用技巧_
- 压缩aspx页面删除多余空格的两种方法_实用技巧_
- asp.net导出excel的简单方法实例_实用技巧_
- asp.net读取excel文件的三种方法示例_实用技巧_
- 使用asp.net MVC4中的Bundle遇到的问题及解决办法分享_实用技巧_
- asp.net输出重写压缩页面文件实例代码_实用技巧_
点击排行
本栏推荐
