How to get a gridview to show all table rows when no text is entered in a dependent textbox?

前端 未结 2 503
臣服心动
臣服心动 2021-01-16 11:40

The below works correctly and filters my gridview based on the text entered in my textbox.

When no text is entered into my textbox I get no results and cannot unders

2条回答
  •  日久生厌
    2021-01-16 12:10

    Instead of coalesce you may have a if block which checks if the @search parameter is empty or not as shown below..

    if @search is not empty 
      SELECT  [table].[column]
      FROM    [table]
      WHERE   [table].[column] LIKE '%' + @Search + '%' OR COALESCE(@Search,'') = ''
    else
      SELECT  [table].[column]
      FROM    [table]
      WHERE   [table].[column]
    

提交回复
热议问题