Hi Team
I have textbox with textmode = "multline" in radGrid Batch editting Mode. After typing multiple line using carriage return (enter key) after each line for example
1. The boy is genius
2. keep coding
When I hit the save changes button I receive the error: Unterminated String Constant.
If I omit the new line i.e 1. The boy is genius. It save perfectly.
I Tried doing something like this. 1.The boy is genius \n 2. Keep Coding. it works and display as multiline in edit mode.
Any Suggestions
Thank You..
I have textbox with textmode = "multline" in radGrid Batch editting Mode. After typing multiple line using carriage return (enter key) after each line for example
1. The boy is genius
2. keep coding
When I hit the save changes button I receive the error: Unterminated String Constant.
If I omit the new line i.e 1. The boy is genius. It save perfectly.
I Tried doing something like this. 1.The boy is genius \n 2. Keep Coding. it works and display as multiline in edit mode.
Any Suggestions
Thank You..
3 Answers, 1 is accepted
0
Accepted
Hello Ali,
There are indeed some limitations when MultiLine mode is used in combination with Batch Editing. What you need to handle new lines with Batch Editing is to store your new lines with "\n" in the database and to manually convert them to "<br />" for the grid (and vice verse).
I have that the following example will help you with implementing this in your actual project:
And the code-behind:
Best Regards,
Konstantin Dikov
Telerik
There are indeed some limitations when MultiLine mode is used in combination with Batch Editing. What you need to handle new lines with Batch Editing is to store your new lines with "\n" in the database and to manually convert them to "<br />" for the grid (and vice verse).
I have that the following example will help you with implementing this in your actual project:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function showContextMenu(e) {
var contextMenu = $find("<%=AddRecordMenu.ClientID%>");
contextMenu.show(e);
}
function itemClicked(sender, args) {
if (args.get_item().get_value() == "1") {
var grid = $find("<%=RadGrid1.ClientID%>");
var masterTable = grid.get_masterTableView();
var batchManager = grid.get_batchEditingManager();
batchManager.addNewRecord(masterTable);
}
else {
// your custom logic
}
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadContextMenu
runat
=
"server"
ID
=
"AddRecordMenu"
OnClientItemClicked
=
"itemClicked"
>
<
Items
>
<
telerik:RadMenuItem
Text
=
"Add in grid"
Value
=
"1"
></
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Text
=
"Add in popup"
Value
=
"2"
></
telerik:RadMenuItem
>
</
Items
>
</
telerik:RadContextMenu
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnPreRender
=
"RadGrid1_PreRender"
>
<
MasterTableView
EditMode
=
"Batch"
CommandItemDisplay
=
"Top"
>
</
MasterTableView
>
</
telerik:RadGrid
>
And the code-behind:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
DataTable table =
new
DataTable();
table.Columns.Add(
"ID"
,
typeof
(
int
));
table.Columns.Add(
"Comment"
,
typeof
(
string
));
for
(
int
i = 0; i < 5; i++)
{
table.Rows.Add(i,
"Test \n \n test"
);
}
(sender
as
RadGrid).DataSource = table;
}
public
string
replaceNewlines(
string
input)
{
return
input.Replace(
"\n"
,
"<br />"
);
}
Best Regards,
Konstantin Dikov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0

Ali
Top achievements
Rank 1
answered on 18 Dec 2014, 11:33 AM
Thanks for the resolution
I think it will be best to implement it in the new controls
I think it will be best to implement it in the new controls
0
Hello Ali,
I have pasted the wrong markup in my previous post, for which I apologize.
Please look at the correct markup and the code-behind of the workaround:
And the code-behind:
Regards,
Konstantin Dikov
Telerik
I have pasted the wrong markup in my previous post, for which I apologize.
Please look at the correct markup and the code-behind of the workaround:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function getCellValue(sender, args) {
if (args.get_columnUniqueName() == "Comment") {
var labelValue = args.get_cell().children[0].innerHTML;
var replacedNewLines = labelValue.trim().replace(/<
br
>/g, "\n");
replacedNewLines = replacedNewLines.trim().replace(/<
BR
>/g, "\n");
args.set_value(replacedNewLines);
args.set_cancel(true);
}
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowMultiRowEdit
=
"true"
Width
=
"400px"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
EditMode
=
"Batch"
CommandItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Notizen"
UniqueName
=
"Comment"
>
<
ItemTemplate
>
<
asp:Literal
Text='<%# replaceNewlines(Eval("Comment").ToString()) %>' runat="server" ID="Literal_Notizen"></
asp:Literal
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadTextBox
runat
=
"server"
ID
=
"CommentTB"
TextMode
=
"MultiLine"
Width
=
"100%"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnBatchEditGetCellValue
=
"getCellValue"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
And the code-behind:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
DataTable table =
new
DataTable();
table.Columns.Add(
"ID"
,
typeof
(
int
));
table.Columns.Add(
"Comment"
,
typeof
(
string
));
for
(
int
i = 0; i < 5; i++)
{
table.Rows.Add(i,
"Test \n \n test"
);
}
(sender
as
RadGrid).DataSource = table;
}
public
string
replaceNewlines(
string
input)
{
return
input.Replace(
"\n"
,
"<br />"
);
}
Regards,
Konstantin Dikov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.