如何根据我在网格中的搜索获取数据
本文关键字:搜索 获取 数据 网格 何根 | 更新日期: 2023-09-27 17:56:32
在文本框中,我必须键入将在表中搜索的字符串。 如果在 3 列中的任何一列中找到数据,数据将显示在 GridView 中。3 列是标题、说明和关键字。如果选中标题 chk 框,它将搜索标题,如果选中关键字 s,它将在其中搜索。如果未选中任何复选框,则不会在特定列中进行搜索。我有 2 个单选按钮,还需要选择其中一个。如果单击and_radio,它将在两列中搜索数据,如果或单击,则在任何一列中找到 idf 数据将显示....帮忙尝试很久...它必须通过程序来完成。我应该在搜索按钮单击上编写什么代码以在文本框中搜索数据,然后在网格中填充结果我使用的存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER Procedure [dbo].[sp_Normal_Search_Library]
@title AS nvarchar(max),
@Description AS nvarchar(max),
@Keywords AS nvarchar(max),
@Chk_title AS BIT ,
@Chk_Description AS Bit ,
@Chk_Keywords AS BIT,
@RD_AND AS BIT,
@RD_OR AS BIT
AS
if @RD_AND = 1 Begin
if @Chk_title = 1
Begin
Select title from server_des where title Like '%'+@title+'%'
End
if @Chk_Description=1
Begin
Select Description from server_des where Description Like '%'+@Description+'%'
End
if @Chk_Keywords=1
Begin
Select Keywords from server_des where Keywords Like '%'+@Keywords+'%'
End
if @Chk_title = 1 AND @Chk_Description = 1
Begin
Select title, Description from server_des where title Like '%'+ @title+'%' AND Description Like '%'+@Description+'%'
End
if @Chk_Description=1 AND @Chk_Keywords=1
Begin
Select Description, Keywords from server_des where Description Like'%'+@Description+'%' AND Keywords Like '%'+@Keywords+'%'
End
if @Chk_title=1 AND @Chk_Keywords=1
Begin
Select title, Keywords from server_des where title Like'%'+@title+'%' AND Keywords Like'%'+@Keywords+'%'
End
if @Chk_title=1 AND @Description=1 AND @title=1
Begin
Select title,Description, Keywords from server_des where title Like '%'+@title+'%'AND Description Like '%'+@Description+'%' AND Keywords Like '%' +@Keywords+'%'
End
End
ELSE IF @RD_OR=0
Begin
if @Chk_title = 1
Begin
Select title from server_des where title Like'%'+ @title+'%'
End
if @Chk_Description=1
Begin
Select Description from server_des where Description Like '%'+@Description+'%'
End
if @Chk_Keywords=1
Begin
Select Keywords from server_des where Keywords Like '%'+@Keywords+'%'
End
if @Chk_title = 1 AND @Chk_Description = 1
Begin
Select title, Description from server_des where title Like '%'+ @title+'%' AND Description Like '%'+@Description+'%'
End
if @Chk_Description=1 AND @Chk_Keywords=1
Begin
Select Description, Keywords from server_des where Description Like '%'+@Description+'%' AND Keywords Like '%'+@Keywords+'%'
End
if @Chk_title=1 AND @Chk_Keywords=1
Begin
Select title, Keywords from server_des where title Like '%'+@title+'%' AND Keywords Like '%'+@Keywords+'%'
End
if @Chk_title=1 AND @Description=1 AND @title=1
Begin
Select title, Description, Keywords from server_des where title Like'%'+@title+'%'AND Description Like '%'+@Description+'%' AND Keywords Like '%' +@Keywords+'%'
End
End
在业务逻辑中,我创建了方法:
public DataTable Fillgrid(string title,string Description, string Keywords)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["LibrarySql"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "sp_Normal_Search_Library";
cmd.CommandType = CommandType.StoredProcedure;
//string query = "select * from Server_des";
cmd.Parameters.AddWithValue("@title", title);
cmd.Parameters.AddWithValue("@Description",Description);
cmd.Parameters.AddWithValue("@Keywords",Keywords);
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
con.Open();
sda.Fill(dt);
return dt;
现在,如何在 Web 表单的网格中填充数据?
DataGrid.DataSource = Fillgrid("title","description","keyword");
DataGrid.Bind();