-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.

'?

hhh3112
  • 2,167
  • 10
  • 36
  • 55
  • 3
    Is `SqlDataSource1.SelectParameters` valid (!= null)?? Is `SqlDataSource1.SelectParameters["page"]` valid (!= null)?? This is just very basic debugging.... – marc_s Feb 09 '11 at 20:18

2 Answers2

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.

RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262
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.

Kevin Babcock
  • 10,187
  • 19
  • 69
  • 89
  • 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? – Nate Aug 24 '18 at 20:09