简体   繁体   English

数据绑定语法错误

[英]Data-Binding Syntax error

I have a gridview in asp.net web page. 我在asp.net网页中有一个gridview。 The datasource comes sql server table. 数据源来自sql server表。 I want each cell's maximum length less than 50. I got an error. 我希望每个单元格的最大长度小于50。我得到一个错误。

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?) 编译器错误消息:CS1061:'object'不包含'Length'的定义,并且找不到扩展方法'Length'接受类型为'object'的第一个参数(您是否缺少using指令或程序集引用?)

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. 您可以尝试Eval(“ OrgContactName”)。toString()。Length> 50 ....等Eval将返回一个对象,因此如果要访问“ Length”属性,则需要强制转换为String。 Try it out. 试试看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM