This is a migrated thread and some comments may be shown as answers.

Truncate Column Text not working

4 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gerald
Top achievements
Rank 1
Gerald asked on 05 May 2017, 02:36 PM

I have a grid that I open up with all lines editable.  I am trying to strip the first 10 characters off of the text in the ItemDataBound event. I have version 2016.3.1027.40. 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem)
{
GridEditableItem editableItem = e.Item as GridEditableItem;
//string s = "This Works and is longer than 10 characters";
//if (s.Length > 10)
//{
// s = s.Substring(10);
//}
//editableItem["MasterLineItem"].Text = s;

if (editableItem["MasterLineItem"].Text.Length > 10)
{
editableItem["MasterLineItem"].ToolTip = (editableItem["MasterLineItem"].Text).Substring(10);  //THIS DOES NOT WORK
                }
}
}

 

Thanks

4 Answers, 1 is accepted

Sort by
0
Gerald
Top achievements
Rank 1
answered on 05 May 2017, 03:06 PM

EDIT:  I'm trying to set the Text not the ToolTip.

editableItem["MasterLineItem"].Text = (editableItem["MasterLineItem"].Text).Substring(10); //THIS DOES NOT WORK

0
Vessy
Telerik team
answered on 10 May 2017, 11:22 AM
Hi Gerard,

I tested the provided functionality but the cell text in the MasterLineItem column gets truncated successfully at my end. Can you see the video from my test and let me know whether this is the value you need to change?
https://www.screencast.com/t/wo00Et6AdQ

You can find the code I used for my test as of below:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" HeaderStyle-Width="150px" AutoGenerateEditColumn="True"
    OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
    <ClientSettings>
        <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
    </ClientSettings>
</telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = GetData();
}
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem)
    {
        GridEditableItem editableItem = e.Item as GridEditableItem;
 
        if (editableItem["MasterLineItem"].Text.Length > 10)
        {
            editableItem["MasterLineItem"].Text = (editableItem["MasterLineItem"].Text).Substring(10);
        }
    }
}
 
private DataTable GetData()
{
    DataTable dt = new DataTable("data");
    dt.Columns.Add("MasterLineItem", Type.GetType("System.String"));
    dt.Columns.Add("BoundColumn2", Type.GetType("System.Int32"));
    dt.Columns.Add("BoundColumn3", Type.GetType("System.Int32"));
 
    for (int i = 0; i < 50; i++)
    {
        var flag = i % 3 == 0 ? true : false;
        dt.Rows.Add(
            "Some long text 1234567890" + i.ToString(),
            i + 1,
            i + 200000
            );
    }
 
    return dt;
}


Regards,
Vessy
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gerald
Top achievements
Rank 1
answered on 10 May 2017, 04:30 PM

Vessy,

Thanks for the response.  Your video pointed me in the right direction.  My grid uses inline edit mode, all rows are in edit mode, and the column I want to truncate is read only.  By accessing the Literal of the GridEditableitem and truncating that I am seeing the desired results.

My updated code:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem)
    {
        GridEditableItem editableItem = e.Item as GridEditableItem;
 
        if (editableItem.IsInEditMode)
        {
            Literal ltrl = editableItem["MasterLineItem"].Controls[1] as Literal;
            if (ltrl.Text.Length > 10)
            {
                ltrl.Text = ltrl.Text.Substring(10);
            }
        }
    }
}

Regards,

Gerald

0
Vessy
Telerik team
answered on 15 May 2017, 12:17 PM
Hi Gerald,

I am glad to know my answer was helpful for you and you have managed to achieve the target result. As always, feel free to reach us again should any further questions occur.

Regards,
Vessy
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Gerald
Top achievements
Rank 1
Answers by
Gerald
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or