How to use global variables in ObjectDataSource.SelectMethod?
<p>I'm using ListView + DataPager + ObjectDataSource mix. </p>

<p>In the implementation of my SelectMethod of an ObjectDataSource I'd like to access a global variable set in the PageLoad() event (the method will return just the proper number of items per page). Although the variable is initialized in PageLoad() it appears to be null in SelectMethod. How can I change that?</p>

<pre><code>    &lt;asp:ObjectDataSource ID="ItemsObjectDataSource" runat="server" EnablePaging="True"
                        SelectMethod="WrapSearchResults" SelectCountMethod="CountSearchResults"
                        TypeName="Catalogue"&gt;
                        &lt;SelectParameters&gt;
                            &lt;asp:QueryStringParameter Name="startRowIndex" QueryStringField="page" Type="Int32" DefaultValue="0" /&gt;
                            &lt;asp:Parameter Name="maximumRows" Type="Int32" DefaultValue="10" /&gt;
                        &lt;/SelectParameters&gt;
    &lt;/asp:ObjectDataSource&gt;
</code></pre>

<hr>

<pre><code>SearchOption search;
protected void Page_Load(object sender, EventArgs e)
{
    search = new SearchOption(SessionParameters.Get(Session).User);
}

public IEnumerable&lt;ResultWrapper&gt; WrapSearchResults(int startRowIndex, int maximumRows)
{
    search.Limit = maximumRows; &lt;-- null pointer exception
}
</code></pre>
