Nullable (int?) keep throwing non-nullable exception
<p>This is a first that I've encountered this - of course that does't sais a lot, but never the less I need to consult with the collective as my searches while showed that it can be done, I'm not able to work it out.</p>

<p>The issue is that if user leaves the text box empty C# automagically enters zero on the postback and into the database as well. I just want the text box left blank.</p>

<p>I have a class there the property is declared:</p>

<pre><code>private int? _PageNumber = null;

public int? PageNumber
{
    get { return _PageNumber; }
    set { _PageNumber = value; }
}
</code></pre>

<p>The in my code file I have:</p>

<pre><code>if (tbPageNumber.Text != "")
        ia.PageNumber = Convert.ToInt32(tbPageNumber.Text);
    else
        ia.PageNumber = null;
</code></pre>

<p>and this is where I get the exception:</p>

<pre><code>CS0037: Cannot convert null to 'int' because it is a non-nullable value type
</code></pre>

<p>So I thought if I can't change the type, perhaps I can change the output. So I thought perhaps I can fake it by placing this in the texbox's text property:</p>

<pre><code>'&lt;%# Eval("PageNumber") == 0 ? null:Eval("PageNumber") %&gt;'
</code></pre>

<p>This throws <code>CS0019: Operator '==' cannot be applied to operands of type 'object' and 'int'</code> exception.</p>

<p>Why is so damn stubborn???</p>
