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
|