How to limit the characters of a field in gridview?

This is a discussion on How to limit the characters of a field in gridview? within the C# Programming forums, part of the General Programming Boards category; hi guys i list the project descriptions on a field in my gridview, but some of them are too long. ...

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71

    Question How to limit the characters of a field in gridview?

    hi guys

    i list the project descriptions on a field in my gridview, but some of them are too long. i want to limit them like 20 characters of 50 chars can be seen by the user. then pressing a button entire description will be displayed.

    how can i do that?

    waiting your answers.. thanks..

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Are you using Labels? Texboxes?
    In any case, I believe that if you do AutoSize = false (a property) the controls won't change size no matter what the Text is. So just define a size and the rest of the characters wont be displayed.
    Then by pressing a button either have them increase in size or do AutoSize = true (and maybe also do Text += "" so the autosize takes effect)

  3. #3
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    thanks for your reply C_ntua but i could not find any property of gridview. i m using C# with asp.net, may be it is the reason.

    i find a way that helped me.

    it is like that

    Code:
    protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ViewState["description"] = e.Row.Cells[3].Text;
                if (e.Row.Cells[3].Text.Length >= 30)
                {
                    e.Row.Cells[3].Text = e.Row.Cells[3].Text.Substring(0, 30) + "...";
                    e.Row.Cells[3].ToolTip = ViewState["description"].ToString();
                }
            }
        }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 07:00 AM
  2. Strange characters in output to terminal
    By hellogamesmaste in forum C Programming
    Replies: 4
    Last Post: 08-30-2009, 11:25 AM
  3. ascii characters video displaying on tv screen
    By deian in forum C Programming
    Replies: 6
    Last Post: 10-12-2004, 10:46 PM
  4. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2003, 12:23 AM
  5. limit the characters using gets function
    By yukon in forum C Programming
    Replies: 6
    Last Post: 10-08-2001, 03:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21