I have a gridview in asp.net web page. The datasource comes sql server table. I want each cell’s maximum length less than 50.
I got an error.
Thanks for helping me to fix it.
<asp:TemplateField HeaderText="OrgContactName" SortExpression="OrgContactName">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("OrgContactName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# (Eval("OrgContactName").Length>50)?Eval("OrgContactName").SubString(0,50):Eval("OrgContactName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
The error:
Compiler Error Message: CS1061: ‘object’ does not contain a definition for ‘Length’ and no extension method ‘Length’ accepting a first argument of type ‘object’ could be found (are you missing a using directive or an assembly reference?)
You can try Eval(“OrgContactName”).toString().Length>50 …. etc Eval will return an object, so you need to cast as String if you want to access “Length” property. Try it out.