I have a ASP gridview control. I have a ASP label control in the item template column. I bind data to the grid using -
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
</ItemTemplate>
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 Wrap="true"
and limit the column width.
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 -
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("Description").ToString().Substring(0,50) %>' ToolTip='<%# Eval("Description") %>'></asp:Label>
</ItemTemplate>
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.
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.
Is there a way to fix this problem? Can we call a javascript function within Eval() ?