Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Quote:
Index and length must refer to a location within the string.
Parameter name: length

i have got the following code from Internet but when i applied that code i am getting the above error.
XML
<asp:TemplateField>
   <HeaderTemplate>
      Programme
   </HeaderTemplate>
   <ItemTemplate>
      <%#Eval("ProgrammeName").ToString().Substring(0, 10)%>
   </ItemTemplate>
</asp:TemplateField>
Posted

try to fix the length, check the following code.

C#
<![CDATA[<%# Eval("ProgrammeName").ToString().Substring(0, Math.Min(Eval("ProgrammeName").ToString().Length, 10)) %>]]> 
 
Share this answer
 
Comments
sahabiswarup 10-Nov-11 0:04am    
no value displays after using the above code
Use this instead to make sure that text is atleast 10 characters long.
<%#Eval("ProgrammeName").ToString().PadRight(10,' ').Substring(0, 10).Trim() %>
 
Share this answer
 
v2
Comments
sahabiswarup 10-Nov-11 0:08am    
thanks a lot..it works...
Prerak Patel 10-Nov-11 0:12am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900