Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Datagrid: how cut short display of a long description in a datagrid column

Reply
Thread Tools

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

 
 
Brian K. Williams
Guest
Posts: n/a
 
      03-02-2004
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:892E97A1-4165-4771-8467-...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView default column too small for description column from data JB ASP .Net 1 09-21-2009 03:04 PM
Re: Short description under image (like newspapers) Sherm Pendley HTML 0 09-09-2008 01:22 AM
Having compilation error: no match for call to ‘(const __gnu_cxx::hash<long long int>) (const long long int&)’ veryhotsausage C++ 1 07-04-2008 05:41 PM
longs, long longs, short short long ints . . . huh?! David Geering C Programming 15 01-11-2007 09:39 PM
RE: Datagrid: how cut short display of a long description in a datagrid column =?Utf-8?B?U3VyZXNo?= ASP .Net 0 03-02-2004 08:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57