title: ASP.NET - GridView - EditItem - Null Value for Integers?
body: <p>I am using a GridView in asp.net 2.0 and I want to perform inline editing. I am using an object datasource. Because I want to use validation controls on the integer fields in my gridview, I have made them into <code>&lt;TemplateFields&gt;</code> and added a datatype validator and a range validator. This allows me to either have a blank field, or an integer value between 0 and 999.</p>
  
  <p>I am trying to display a "-" when the value of the property is not defined. There is no Null for an integer, so I have decided to use -1 as the value to indicate a Null.</p>
  
  <p>I am reformatting the  to display the "-" if the value is -1.  I do that as follows:</p>
  
  <pre><code>&lt;ItemTemplate&gt;
     &lt;asp:Label ID="lblPC" runat="server" Text='&lt;%# FormatIntegerToText(Eval("PitchCount"),"-") %&gt;'&gt;&lt;/asp:Label&gt;
  &lt;/ItemTemplate&gt;
  </code></pre>
  
  <p>In the code behind I have defined the function FormatIntegerToText as follows:</p>
  
  <pre><code>Protected Function FormatIntegerToText(ByVal value As Object, ByVal nullvalue As String) As String
         ' Make sure value is not null... if so, return "-"
         If value = Null.NullInteger() Then
             Return nullvalue
         Else
             Return value.ToString()
         End If
  End Function
  </code></pre>
  
  <p>All of this works great. Now comes the problem...when I click my Edit button, the <code>&lt;EditItem&gt;</code> is displayed (with textboxes etc) but all the "null" values are displayed as -1</p>
  
  <p>I currently have this as my <code>&lt;EditItemTemplate&gt;</code></p>
  
  <pre><code>&lt;EditItemTemplate&gt;
     &lt;asp:textbox ID="txtPC" runat="server" Text='&lt;%# Bind("PitchCount") %&gt;' width="25" Columns="2"&gt;&lt;/asp:textbox&gt;
     ....a couple of validators....
  &lt;/EditItemTemplate&gt;
  </code></pre>
  
  <p>I though I could do the following to reformat the value that is placed in the text box:</p>
  
  <pre><code>&lt;EditItemTemplate&gt;
     &lt;asp:textbox ID="txtPC" runat="server" Text='&lt;%# FormatIntegerToText(Bind("PitchCount")) %&gt;' width="25" Columns="2"&gt;&lt;/asp:textbox&gt;
  </code></pre>
  
  <p>but when I do this I get a compilation error that Bind is not a recognized function.</p>
  
  <p>My question is, why is this not allowed, and how can I work around it?</p>