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

How to Display Linefeed on a New Line?

1 Answer 253 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Brian asked on 05 Jun 2012, 05:37 PM

I have a feeling that I am overlooking something obvious, yet I cannot figure it out.

My RadGrid has a GridBoundColumn that utilizes a GridTextBoxColumnEditor during in-place edits. The GridTextBoxColumnEditor has TextBoxMode set to MultiLine. While in edit mode, if "Line 1" is typed in, and the Enter key is pressed, and "Line 2" is typed in, the data is displayed like this 1st illustration:

    Line 1
    Line 2

But after I click Save, and the RadGrid returns to View mode (instead of Edit mode), the data appears like this 2nd illustration:

    Line 1  Line 2

If I go back to edit mode, the data appears like the 1st illstration, but then appears like the 2nd illustration after clicking Save or Cancel (return to View mode).

How do I get the View mode to display the data like the 1st illustration? Setting these GridBoundColumn properites, ItemStyle-Wrap="true" and Resizable="true", does nothing in this situation. How do I get the GridBoundColumn to always display the data like the 1st illustration?

Thank you,

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 14 Jun 2012, 09:23 AM
Hi Steven,

The GridBoundColumn will be rendered as TextBox in Edit mode only.Thats why you were able to set the TextBoxMode to multiLine.In ViewMode the GridBoundColumn can be only accessed as a cell.So cannot give the MultiLine Property.

One suggestion is to add a TextBox to the TableCell of the particular column and for showing the updated result as it is.Please take a look into the following code snippet i tried.

<telerik:RadGrid ID="rgDepartment" runat="server" Skin="Office2007"
            onitemdatabound="rgDepartment_ItemDataBound" >
    <MasterTableView EditMode="InPlace"
            <telerik:GridBoundColumn DataField="OrderID"
              <telerik:GridBoundColumn DataField="ShipName"
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />

public static string connection = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
public SqlCommand SqlCommand = new SqlCommand();
DataTable dt1 = new DataTable();
protected void rgDepartment_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    string selectQuery1 = "select top 10 * from Orders";
    SqlDataAdapter adapter1 = new SqlDataAdapter(SelectQuery1, conn);
    rgDepartment.DataSource = dt1;
protected void rgDepartment_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    if (e.Item is GridDataItem)
        GridDataItem item = (GridDataItem)e.Item;
        TableCell cel = (TableCell)item["ShipName"]; //accessing the TableCell
        TextBox TextBox1 = new TextBox();
        TextBox1.Width = 106;
        TextBox1.Text = cel.Text;
        TextBox1.ID = "textbox";
        TextBox1.TextMode = TextBoxMode.MultiLine; 
        cel.Controls.Add(TextBox1);  // adding textbox in view mode
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       GridEditableItem editItem = (GridEditableItem)e.Item;
       GridTextBoxColumnEditor txteditor = (GridTextBoxColumnEditor)editMan.GetColumnEditor("ShipName");
       txteditor.TextBoxMode = TextBoxMode.MultiLine;
       TextBox txt = (TextBox)editItem.FindControl("textbox");
       txt.Visible = false; //making textbox invisible in edit mode

Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 2
Share this question