Why if i use the following instruction in the code behind:
SqlDataSource1.SelectParameters["page"].DefaultValue = "0";
I get 'System.NullReferenceException: Object reference not set to an instance of an object.
'?
Why if i use the following instruction in the code behind:
SqlDataSource1.SelectParameters["page"].DefaultValue = "0";
I get 'System.NullReferenceException: Object reference not set to an instance of an object.
'?
The only two objects involves in that single statement are (bold)
SqlDataSource1.SelectParameters["page"].DefaultValue
SqlDataSource1.SelectParameters["page"].DefaultValue
So one of them must be null. When looking at this together with your previous question, it is because you have not yet added the "page" parameter to SqlDataSource1
.
Either your SqlDataSource
object is null or its SelectParameters
collection doesn't have an entry for "page". Check that you have defined that select parameter appropriately.