I haveasp:GridView
displaying client requests using asp:SqlDataSource
. I want to limit displayed information by client:
我有一个:GridView使用asp:SqlDataSource显示客户端请求。我想限制客户显示的信息:
View.aspx
has to display everything, View.aspx?client=1
has to display only requests from client ID #1.
View.aspx必须显示所有内容,View.aspx?client = 1必须只显示来自客户端ID#1的请求。
So I'm using <asp:QueryStringParameter Name="client" QueryStringField="client" />
for query "EXEC getRequests @client"
.
所以我使用
Everything works properly when some client is specified. But don't - if not.
指定某个客户端时,一切正常。但不要 - 如果不是。
I tested my SP using SSMS - it works properly in both cases - when parameter is specified and when it isn't (NULL
passed explicitly).
我使用SSMS测试了我的SP - 它在两种情况下都正常工作 - 指定参数时和不指定参数时(明确地传递NULL)。
What have I do?
我做了什么?
2 个解决方案
#1
16
SqlDataSource won't fire if any of it's parameters are null, unless you specify otherwise:
除非您另行指定,否则如果SqlDataSource的任何参数为null,则不会触发它:
<asp:SqlDataSource CancelSelectOnNullParameter="False" />
It might also be necessary to add a null default value to your querystring parameter:
可能还需要在querystring参数中添加一个null默认值:
<asp:QueryStringParameter Name="client" QueryStringField="client" DefaultValue="" ConvertEmptyStringToNull="True" />
#2
2
You need to define a Default value to the parameter for those situations, for example:
您需要为这些情况的参数定义默认值,例如:
<asp:QueryStringParameter Name="client" QueryStringField="client" DefaultValue="0"/>
and then in the SP you need verify if the client is 0, return all the clients, otherwise the specific one.
然后在SP中,您需要验证客户端是否为0,返回所有客户端,否则返回特定客户端。
#1
16
SqlDataSource won't fire if any of it's parameters are null, unless you specify otherwise:
除非您另行指定,否则如果SqlDataSource的任何参数为null,则不会触发它:
<asp:SqlDataSource CancelSelectOnNullParameter="False" />
It might also be necessary to add a null default value to your querystring parameter:
可能还需要在querystring参数中添加一个null默认值:
<asp:QueryStringParameter Name="client" QueryStringField="client" DefaultValue="" ConvertEmptyStringToNull="True" />
#2
2
You need to define a Default value to the parameter for those situations, for example:
您需要为这些情况的参数定义默认值,例如:
<asp:QueryStringParameter Name="client" QueryStringField="client" DefaultValue="0"/>
and then in the SP you need verify if the client is 0, return all the clients, otherwise the specific one.
然后在SP中,您需要验证客户端是否为0,返回所有客户端,否则返回特定客户端。