-1

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.

'?

1
  • 3
    Is SqlDataSource1.SelectParameters valid (!= null)?? Is SqlDataSource1.SelectParameters["page"] valid (!= null)?? This is just very basic debugging.... Commented Feb 9, 2011 at 20:18

2 Answers 2

5

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.

1

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.

1
  • Parameter must be one of Control, Cookie, Form, Profile, QueryString, Session or Route. Since I didn't create a session variable or a cookie I didn't try those. I tried the others and they all failed. How do I create the parameter? Commented Aug 24, 2018 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.