通过asp.net中的转发器搜索记录

时间:2014-01-23 18:56:43

标签: c# asp.net search repeater

我首先尝试在asp.net中搜索记录,然后创建存储过程:

ALTER procedure [dbo].[spsearchdocuments]
   @Name nvarchar(50)  
as   
   SELECT     
      dbo.DocumentInfo.DocID as DocumentID, 
      dbo.DocumentInfo.DocName as DocumentName, 
      dbo.DocumentInfo.Uploadfile as FileUploaded,
      dbo.DocumentInfo.UploadedDate as UploadedDate,
      dbo.Department.DepType as Department, 
      dbo.DocType.DocType as Document,
      dbo.DocumentInfo.UploadedBy as UploadedBy, 
      dbo.Approval.AppoveBy, dbo.ApproveType.ApproveType as Status
   FROM         
      dbo.DocumentInfo 
   INNER JOIN
      dbo.Approval ON dbo.DocumentInfo.DocID = dbo.Approval.DocID 
   INNER JOIN
      dbo.ApproveType ON dbo.Approval.ApproveID = dbo.ApproveType.ApproveID 
   INNER JOIN
      dbo.Department ON dbo.DocumentInfo.DepID = dbo.Department.DepID 
   INNER JOIN
      dbo.DocType ON dbo.DocumentInfo.DocTypeID = dbo.DocType.DocTypeID
   WHERE
      [DocName] like @Name+'%'

然后当我在这样的函数中调用此过程时

public DataTable searchdcouments(string Name )
{
    return db.ExecuteDataSet("spsearchdocuments", new object[] { Name }).Tables[0];
}

当我以.aspx形式在此搜索按钮后面调用此函数

protected void Btn_submits_Click(object sender, EventArgs e)
{         
    Repeater4.DataSource = sear.searchdcouments(searz.Text);
    Repeater4.DataBind();           
}

当我调试我的项目并编写关键字时,它不会向我显示数据库中存在记录的任何记录

看看下面的图片

当我输入关键字

keyword

当我点击搜索按钮时,它会显示我这样的

show no records.

1 个答案:

答案 0 :(得分:1)

您似乎错误地输入了关键字。它是" ERP系统"在DB和" erpssystem"在搜索框中

在评论后修改

"像google"表示每次搜索字符串更改时都必须运行选择,例如用户输入/删除一封信。

要执行此操作,请使用 searz 对象并为其添加处理程序""值已更改"事件。

第二次修改

假设它是TextBox并且您正在使用VisualStudio,请打开 searz 的属性并查找TextChanged事件。双击它将创建TextChanged事件处理程序,您将这样填写:

protected void searz_TextChanged(object sender, EventArgs e)
{
    Repeater4.DataSource = sear.searchdcouments(searz.Text);
    Repeater4.DataBind();
}