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


the below works correctly , filters gridview based on text entered in textbox.

when no text entered textbox no results , cannot understand why.

my question

how gridview show all table rows when no text entered in textbox?

mssql

@search nvarchar(50)  select  [table].[column]    [table]   [table].[column] '%' + @search + '%' or coalesce(@search,'') = '' 

markup

<asp:textbox id="txtsearch" runat="server" text=""/>  <asp:sqldatasource id="sqlsearch" runat="server" selectcommand="spsearch" selectcommandtype="storedprocedure">   <selectparameters>     <asp:controlparameter type="string" name="search" controlid="txtsearch" propertyname="text"/>   </selectparameters>  </asp:sqldatasource> 

results gridview

i have tried , tested many methods found on here return 0 results when string empty.

look @ cancelselectonnullparameter - default, prevents select command being called when select parameter's value null. after setting false, select sp still called if text box empty, e.g.

<asp:sqldatasource id="sqlsearch" runat="server"      cancelselectonnullparameter="false" ...> </asp:sqldatasource> 

the sqldatasource seems bit misleading me here, because textbox.text returns string.empty when it's empty, not null, therefore wouldn't expect have mess cancelselectonnullparameter textbox, seems have to.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -