title: Display a truncated string using Eval
body: <p>I have a ASP gridview control. I have a ASP label control in the item template column. I bind data to the grid using - </p>
  
  <pre><code>&lt;ItemTemplate&gt;
          &lt;asp:Label ID="lblDesc" runat="server" Text='&lt;%# Eval("Description") %&gt;'&gt;&lt;/asp:Label&gt;
  &lt;/ItemTemplate&gt;
  </code></pre>
  
  <p>But, the value of this string can be upto 80 characters. But, I cannot afford to have the column length to be so high. And, there are limitations so I cannot use <code>Wrap="true"</code> and limit the column width.</p>
  
  <p>So, I figured the solution could be to display only about 50 characters in the grid and display the entire string as a tool tip. I managed to do this by using this - </p>
  
  <pre><code>&lt;ItemTemplate&gt;
          &lt;asp:Label ID="lblDesc" runat="server" Text='&lt;%# Eval("Description").ToString().Substring(0,50) %&gt;' ToolTip='&lt;%# Eval("Description") %&gt;'&gt;&lt;/asp:Label&gt;
  &lt;/ItemTemplate&gt;
  </code></pre>
  
  <p>This displays the first 50 characters of the string in the grid column. And, the complete string is displayed as a tool tip when the mouse pointer hovers over the text. But, the problem arises when the string length is less than 50 characters. In this case, an exception is thrown.</p>
  
  <p>I tried modifying this piece of code to allow conditional display by checking for the string length. But, I could not get this to work. </p>
  
  <p>Is there a way to fix this problem? Can we call a javascript function within Eval() ? </p>