Re: Datagrid: how cut short display of a long description in a datagrid column

Discussion in 'ASP .Net' started by Brian K. Williams, Mar 2, 2004.

  1. You could overide the FormatDataValue. I have attached the code that I use.

    public class RLString : BoundColumn
    {
    // PROPERTY: Charater Limit
    private int charLimit = 0;
    public int CharLimit
    {
    get { return charLimit; }
    set { charLimit=value; }
    }

    protected override string FormatDataValue(object dataValue)
    {
    if (dataValue != null && dataValue != DBNull.Value)
    {
    string strOut = "";
    string strCheck = "";
    string strIn = clsUtils.cleanStringIn(dataValue.ToString());
    strCheck = Truncate(dataValue.ToString());
    if(strCheck.IndexOf("...") > -1)
    {
    strOut += "<label title=" + "\"" + strIn + "\"" + ">" + strCheck +
    "</label>";
    }
    else
    {
    strOut += "<label>" + strCheck + "</label>";
    }
    return strOut;
    }
    else
    {
    return dataValue.ToString();
    }
    }


    string Truncate(string input)
    {
    string output = input;
    if (output.Length > charLimit && charLimit > 0)
    {
    output = output.Substring(0,charLimit);
    if (input.Substring(output.Length,1) != " ")
    {
    int LastSpace = output.LastIndexOf(" ");
    if (LastSpace != -1)
    {
    output = output.Substring(0,LastSpace);
    }
    }
    output += "...";
    }
    return output;
    }
    }

    "Reza" <> wrote in message
    news:...
    > Hi,
    >
    > I have a description column in my datagrid. I have tried to give it a fix

    length, no length at all, or even a percentage, but it always to seem to
    have mind of its own!
    >
    > What I like to be able to do is. show something like this:
    > "this is the description..." or just only show part of the text that fits

    within the length!
    >
    > Thanks in advance for your response.
    > Reza
    Brian K. Williams, Mar 2, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    515
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  2. David Geering

    longs, long longs, short short long ints . . . huh?!

    David Geering, Jan 8, 2007, in forum: C Programming
    Replies:
    15
    Views:
    546
    Keith Thompson
    Jan 11, 2007
  3. Sherm Pendley
    Replies:
    0
    Views:
    468
    Sherm Pendley
    Sep 9, 2008
  4. Jonathan N. Little
    Replies:
    0
    Views:
    422
    Jonathan N. Little
    Sep 9, 2008
  5. JB
    Replies:
    1
    Views:
    1,139
Loading...

Share This Page