Gridview and Empty Textbox .net 2.0

P

paulmac106

Hi,

I have a gridview based on a SQL stored procedure. I then want to let
the user filter the results by 4 textboxes. When all 4 textboxes have
"some" search criteria the gridview works fine, but if even one is left
blank the gridview doesn't return any records. When I test the stored
procedure itself it works fine. Can you help me work with the empty
textboxes.

thanks,
Paul
 
H

Hans Kesting

Hi,
I have a gridview based on a SQL stored procedure. I then want to let
the user filter the results by 4 textboxes. When all 4 textboxes have
"some" search criteria the gridview works fine, but if even one is left
blank the gridview doesn't return any records. When I test the stored
procedure itself it works fine. Can you help me work with the empty
textboxes.

thanks,
Paul

What will the query be when you have empty textboxes?
How did you test the stored procedure?

An empty textbox will have an "empty string" as value, not "null",
maybe that's the problem.

Can you use SqlProfiler to check what is executed in SqlServer?

Hans Kesting
 
Joined
Sep 20, 2006
Messages
1
Reaction score
0
Workaround

I had the same problem. SQL Profiler showed me that the SQL Server was not called to execute any instruction if the textbox was empty.
Here is a workaround:
1. Add DefaultValue=" " (the space char) to the textbox definition. For instance, let´s call the textbox name attribute to "cara".
2. Change the query string:
"select * from notas where charindex(@cara,caratula)=1" was supposed to return all records where the field caratula started with the value of cara.
Now, it must read:
"select * from notas where charindex(ltrim(@cara),caratula)=1"

It seems that ASP.Net needs all fields to have some value to launch the query execution.

Hope this helps,

Pato.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top