I have a gridview taking data from object data source. The object data source is taking data from a method which takes one parameter (string). The parameter is supplied from page url using querystring, and the default value is set to null. In the method taking parameter, I am trying to check if the parameter is null return all data else return data
with id got from the parameter – eg. code.
public list<string> MyMethod (string param)
{
if(param == null)
{
return // all
}
else
{
return // id with param
}
}
I tried to debug the program and the param is actually null but the if () statement is always going to “false” condition. i.e. param == null always evaluating to false. I tried String.IsNullorEmpty(param), and it still is evaluating to false. I don’t understand what the problem is. Please help.
Many Thanks.

Have you tried stepping through and debugging (assuming you’re using visual studio)?
Put a breakpoint on your method signature and then hover over with your mouse on the param variable to see what it’s value is after each step.
Debugging will help you identify the source of issues like this pretty fast.
Edit
The screenshot you added shows your param variable is equal to the string “null”, not
null.You can change your if statement to if(param == “null”) and that should work, but the real fix for this is most likely to not use the string “null” at all so that’ll require editing wherever you assign the variable you pass to the function.
Also, your code sample is param == null yet your screenshot is param != null. The != means not equal, I’m not sure if that’s just a typo or you haven’t noticed.