
prayag ganoje
Top achievements
Rank 1
prayag ganoje
asked on 27 Apr 2011, 07:01 PM
Hello,
I am do have data extending the column width. But I want to row without data wrap and truncated row should displayed with "..." extension. I do have a dataset as a datasource for the grid. Is it possible with some string format to achieve this ? Or can you suggest some better method to do this ?
I am do have data extending the column width. But I want to row without data wrap and truncated row should displayed with "..." extension. I do have a dataset as a datasource for the grid. Is it possible with some string format to achieve this ? Or can you suggest some better method to do this ?
4 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 28 Apr 2011, 06:34 AM
Hello Prayag,
In order to achieve this, check for the Length of the cell text and then set ToolTip. Try the following snippet code by attaching ItemDataBound event to your RadGrid. Hope this helps you.
C#:
Thanks,
Princy.
In order to achieve this, check for the Length of the cell text and then set ToolTip. Try the following snippet code by attaching ItemDataBound event to your RadGrid. Hope this helps you.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if
(item[
"ColumnUniqueName"
].Text.Length > 4)
{
item[
"ColumnUniqueName"
].ToolTip = item[
"ColumnUniqueName"
].Text.ToString();
// Set the Tooltip
item[
"ColumnUniqueName"
].Text = (item[
"ColumnUniqueName"
].Text).Substring(0, 5) +
"..."
;
}
}
}
Thanks,
Princy.
0

Derek
Top achievements
Rank 1
answered on 25 Sep 2011, 07:31 PM
Any code examples for how to accomplish this when using a column containing HTML? There is a column containing RadEditor content, so it's not as simple as just truncating the content since the content contains html content as well as actual text.
0

Jesse
Top achievements
Rank 1
answered on 01 Jul 2014, 05:20 PM
Sorry to resurrect this, but I haven't been able to find a great answer for this question.
I have an option to remove columns in my radgrid, so the user can choose how many columns they want to show. If they show all columns, I'd want to truncate the text much earlier than if only one column is being shown.
Would I have to do something like this?
I have an option to remove columns in my radgrid, so the user can choose how many columns they want to show. If they show all columns, I'd want to truncate the text much earlier than if only one column is being shown.
Would I have to do something like this?
Telerik.WebControls.GridDataItem item = (Telerik.WebControls.GridDataItem)e.Item;
int
numberOfCharacters = (
int
)(item[
"ColumnUniqueName"
].Width.Value / 9);
// 9 being an arbitrary number of about how many pixels per character
if
(item[
"ColumnUniqueName"
].Text.Length > numberOfCharacters)
{
item[
"ColumnUniqueName"
].ToolTip = item[
"ColumnUniqueName"
].Text;
// Set the Tooltip
item[
"ColumnUniqueName"
].Text = (item[
"ColumnUniqueName"
].Text).Substring(0, numberOfCharacters + 1) +
"..."
;
}
0

Princy
Top achievements
Rank 2
answered on 02 Jul 2014, 06:07 AM
Hi Jesse,
Yes you can use the above code to truncate the Text.
C#:
Another way to obtain ellipsis is using CSS as shown below:
CSS:
Thanks,
Princy
Yes you can use the above code to truncate the Text.
C#:
item[
"ColumnUniqueName"
].Text = (item[
"ColumnUniqueName"
].Text).Substring(0, 9) +
"..."
;
Another way to obtain ellipsis is using CSS as shown below:
CSS:
.RadGrid td
{
white-space
:
nowrap
;
text-
overflow
: ellipsis;
}
Thanks,
Princy