2012-05-15 2 views
0

나는 asp.net 웹 페이지에서 gridview 있습니다. 데이터 소스에는 SQL Server 테이블이 있습니다. 각 셀의 최대 길이가 50 미만이 되길 원합니다. 오류가 있습니다.데이터 바인딩 구문 오류

고맙습니다. 고맙습니다.

<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> 

오류 :.. 당신이 캐스팅 할 필요가 있으므로

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?)

+0

분명히 TemplateField는 Length 속성을 가질 수 없습니다. 또는 적어도 Eval ("OrgContactName") 일 수도 있습니다. Text.Length. 을 사용하여 을 변경할 수 있습니까? –

답변

0

당신은 평가 ("OrgContactName")을 시도 할 수 toString()를 길이> 50 .... 등 평가는 객체를 반환합니다 Length 속성에 액세스하려면 String으로 설정합니다. 그것을 밖으로 시도하십시오.

관련 문제