Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4554084
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:02:25+00:00 2026-05-21T17:02:25+00:00

In an ASP.NET GridView is it possible to truncate the displayed text but yet

  • 0

In an ASP.NET GridView is it possible to truncate the displayed text but yet keep the whole string so that it can be displayed in a tooltip on hover over?

I have a code behind function written as follows:

public static string TruncateString(string stringToTruncate, int length)
{
   return stringToTruncate.Length > length ?
      stringToTruncate.Substring(0, length) + "..." : 
      stringToTruncate;
}

Switching to the .aspx page I have a GridView created thereon. This is bound to the contents of a custom object which is filled from the results of a sproc.

For the purposes of this let’s assume the field is called BigNVarCharField, autogeneration of columns is turned off and the usual GridView markup is in place.

<asp:BoundField DataField="BigNVarCharField" HeaderText="Big field preview" Visible="true">

I thought that I should be able to do something like use the DataFormatString attribute thus but it doesn’t seem to be working

DataFormatString = '<%#HelperFunctions.TruncateString(Convert.ToString(Eval("BigNVarCharField")))%>'

I don’t want to truncate it in the database or the business logic as I want to be able to display it in a tooltip on hover over the column in question.

The site is already using jQuery so that can be used for the tooltip if needs be.

EDIT: 2011-04-23 How it worked out finally

<asp:TemplateField HeaderText="Big field preview">
<EditItemTemplate>
    <asp:TextBox ID="txtBigNVarCharField" runat="server" Text='<%# Bind("BigNVarCharField") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
    <asp:Label ID="lblBigNVarCharField" runat="server" Text='<%# HelperFunctions.TruncateString(DataBinder.Eval(Container.DataItem,"BigNVarCharField").ToString(), 50)%>' ToolTip='<%#Eval("BigNVarCharField")%>'></asp:Label>
</ItemTemplate>

Marking Chad’s one as the accepted answer as that was what steered me in the correct direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:02:26+00:00Added an answer on May 21, 2026 at 5:02 pm

    Convert this to a template field then insert your as label text. I would probably use the row databound event to handle the logic but you may be able to accomplish it in the markup.

    The DataFormatString is good for numbers and dates but will not do what you are looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Jquery Accordion and I have a asp.net GridView below that. When
I'm trying to wrap my head around custom paging in the ASP.NET Gridview, but
It it possible to enable validation in an ASP.NET GridView purely declaratively? What I've
Regarding ASP.NET's GridView server control: Can I bind to a datasource in the code-behind,
Is it possible to populate asp.net GridView with data and operate on those data
I have an asp.net GridView that I use the tablesorter on: $(document).ready(function() { $([id$='_myGridView']).tablesorter({
I have an ASP.NET GridView which has columns that look like this: | Foo
i have an asp.net c# application. my gridview has a datasource that has 2
Is it possible to develop a whole asp.net web form with jquery ajax instead
I'm not sure if this is possible in ASP.NET, but here is the problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.