search keywords from database and display records in gridview [Resolved]

Posted by Shitalr under ASP.NET on 8/27/2013 | Points: 10 | Views : 3662 | Status : [Member] | Replies : 3
hi,
I have to search records from database and display it in gridview i have done that but what i want is the textbox.text=search
if u enter something then textbox value become that text if u enter nthing and click on page then textbox.text=search again what should i do for this.




Responses

Posted by: Bandi on: 8/27/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
If you wish to have Stored Procedure to get result then use the following
-- Create stored procedure in database
CREATE PROCEDURE USP_SearchString

( @P_SearchStr VARCHAR(50))
AS
BEGIN
SELECT * FROM TablleName WHERE ColumnName = @P_SearchStr OR @P_SearchStr IS NULL
END


call above procedure in application. use result coming from Procedure as Data source of GridView
http://www.codeproject.com/Questions/403000/Grid-View-Binding-using-Stored-Procedure
http://msmvps.com/blogs/deborahk/archive/2009/07/07/dal-retrieve-a-datatable-using-a-stored-procedure.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shitalr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/27/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
>>if u enter nthing and click on page then textbox.text=search again what should i do for this.
If there is no any search string usually we will display all records from table(in database)

For that check for the condition whenever textbox is empty and then display all records
if ( TextBox.Text IS NOT NULL)

{
SELECT values with search string condition
}
else
{
-- SELECT all records without any condition
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shitalr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Taanu51 on: 8/27/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

If the Textbox is empty .it will display all the records otherwise it will display records based on keyword.Following is the example it may helps you

http://www.developerscode.com/2012/01/implementing-date-search-functionality.html

Tanisha Sayyad
.Net and Android Developer
INDIA(Andhra Pradesh)

Shitalr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response