2011-05-13 100 views
1

在文本框中,我必須鍵入將在表中搜索的字符串。如果在3列中的任何一列中找到數據,數據將顯示在gridview中.3列是標題,描述和關鍵字。如果選中標題框,它將搜索標題,如果檢查到關鍵字,它將搜索它。如果任何複選框未被選中,則不會在特定列中進行搜索。我有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 '%'[email protected]+'%' 
End  
if @Chk_Description=1 
    Begin 
    Select Description from server_des where Description Like '%'[email protected]+'%' 
     End  
if @Chk_Keywords=1 
    Begin 
     Select Keywords from server_des where Keywords Like '%'[email protected]+'%' 
     End  
if @Chk_title = 1 AND @Chk_Description = 1 
     Begin 
    Select title, Description from server_des where title Like '%'+ @title+'%' AND Description Like '%'[email protected]+'%' 
     End 
    if @Chk_Description=1 AND @Chk_Keywords=1 
    Begin  
Select Description, Keywords from server_des where Description Like'%'[email protected]+'%' AND Keywords Like '%'[email protected]+'%' 
    End 
    if @Chk_title=1 AND @Chk_Keywords=1 
     Begin 
    Select title, Keywords from server_des where title Like'%'[email protected]+'%' AND Keywords Like'%'[email protected]+'%'   
End  
if @Chk_title=1 AND @Description=1 AND @title=1  
    Begin  
Select title,Description, Keywords from server_des where title Like '%'[email protected]+'%'AND Description Like '%'[email protected]+'%' AND Keywords Like '%' [email protected]+'%' 
     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 '%'[email protected]+'%' 
     End  
if @Chk_Keywords=1 
    Begin 
     Select Keywords from server_des where Keywords Like '%'[email protected]+'%' 
     End  
if @Chk_title = 1 AND @Chk_Description = 1 
    Begin 
    Select title, Description from server_des where title Like '%'+ @title+'%' AND Description Like '%'[email protected]+'%' 
     End  
if @Chk_Description=1 AND @Chk_Keywords=1  
Begin  
Select Description, Keywords from server_des where Description Like '%'[email protected]+'%' AND Keywords Like '%'[email protected]+'%'  
    End 
    if @Chk_title=1 AND @Chk_Keywords=1 
     Begin 
    Select title, Keywords from server_des where title Like '%'[email protected]+'%' AND Keywords Like '%'[email protected]+'%' 
    End 
    if @Chk_title=1 AND @Description=1 AND @title=1  
    Begin 
    Select title, Description, Keywords from server_des where title Like'%'[email protected]+'%'AND Description Like '%'[email protected]+'%' AND Keywords Like '%' [email protected]+'%' 
     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表單上的網格中填充數據?

回答

0

DataGrid.DataSource = Fillgrid("title","description","keyword"); DataGrid.Bind();

+0

GOT IT DONE THANKS – Aishna 2011-05-13 08:48:01

相關問題