Limit Text in GridView Text c#

Hai All,

           Today i came to face a situation in which is hould limit the text in a GridView in ASP.Net, C#, So i Just want to share it with you all For a help


use the Following code to limit your text accordingly





 <asp:TemplateField HeaderText="Description" >  
                   <ItemTemplate>  
                     <asp:LinkButton ID="lnkBtnId" runat="server" Text='<%# ((string)Eval("description")).Length < 40? Eval("description") :((string)Eval("description")).Substring(0,40) + "..."%>'  
                       CommandName='<%# Eval("raw_id") %>' OnClick="lnkBtnId_Click"></asp:LinkButton>  
                   </ItemTemplate>  
                 </asp:TemplateField>  

Change the "description"  to your datafiled and Change the "40" to your desired limit of count to see it in a properway in the Gridview


Thanks

SHARE

Gibin Francis

Hi. I’m Software Engineer in India. I’m Web Developer, Creative Coder, Web Designer, logo Designer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Designer. Inspired to make things looks better and Do the this in the best way.

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment