Telerik Rad Editor
Example With Mail Merge
Custom radeditor dropdown binding from code behind
Step 1 :- Rad Editor
Design
<telerik:RadEditor runat="server" ID="RadEditorMailMerge" SkinID="DefaultSetOfTools"
EnableResize="true" Visible="false" ContentFilters="MakeUrlsAbsolute,FixEnclosingP"
EditModes="Design" Height="250px" Width="750px" ContentAreaMode="Iframe"
AutoResizeHeight="false" Font-Size="Smaller" OnClientCommandExecuting="OnClientCommandExecuting">
<ExportSettings OpenInNewWindow="true">
</ExportSettings>
<Tools>
<telerik:EditorToolGroup>
<telerik:EditorTool Name="Bold" />
<telerik:EditorTool Name="Italic" />
<telerik:EditorTool Name="Underline" />
<telerik:EditorTool Name="Cut" />
<telerik:EditorTool Name="Copy" />
<telerik:EditorTool Name="Paste" />
<telerik:EditorTool Name="FontName" />
<telerik:EditorTool Name="FontSize" />
<telerik:EditorTool Name="ForeColor" />
<telerik:EditorTool Name="BackColor" />
<telerik:EditorTool Name="JustifyLeft" />
<telerik:EditorTool Name="JustifyFull" />
<telerik:EditorTool Name="JustifyCenter" />
<telerik:EditorTool Name="JustifyRight" />
</telerik:EditorToolGroup>
</Tools>
<ImageManager ViewPaths="~/InteractionImages,~/InteractionImages"
UploadPaths="~/InteractionImages,~/InteractionImages"
DeletePaths="~/InteractionImages,~/InteractionImages"
EnableAsyncUpload="true"></ImageManager>
<TrackChangesSettings CanAcceptTrackChanges="False" />
</telerik:RadEditor>
Step 2:- For Step 2 Write the code for
OnClientCommandExecuting="OnClientCommandExecuting"
this event
function OnClientCommandExecuting(editor, args)
{
debugger;
////alert('LOKESH');
var name = args.get_name();
var val = args.get_value();
if (name == "General") {
editor.pasteHtml(val);
args.set_cancel(true);
}
else if (name == "Partner/Lead") {
editor.pasteHtml(val);
args.set_cancel(true);
}
else if (name == "Pledge") {
editor.pasteHtml(val);
args.set_cancel(true);
} else if (name == "Payment") {
editor.pasteHtml(val);
args.set_cancel(true);
}
debugger;
}
For above image to load the dropdowns
use the below code
private void ConfigureMailMergeTools()
{
EditorToolGroup mailMergeTools = new EditorToolGroup();
EditorDropDown addFieldToolGeneral =
new EditorDropDown("General");
addFieldToolGeneral.Text = "General";
addFieldToolGeneral.ShowText = true;
addFieldToolGeneral.ShowIcon = false;
PopulateFieldsTool(addFieldToolGeneral, Constants.InteractionGeneral);
mailMergeTools.Tools.Add(addFieldToolGeneral);
EditorDropDown
addFieldToolPartnerOrLead = new EditorDropDown("Partner/Lead");
addFieldToolPartnerOrLead.Text = "Partner/Lead";
addFieldToolPartnerOrLead.ShowText
= true;
addFieldToolPartnerOrLead.ShowIcon
= false;
PopulateFieldsTool(addFieldToolPartnerOrLead, Constants.InteractionLead);
mailMergeTools.Tools.Add(addFieldToolPartnerOrLead);
EditorDropDown addFieldToolPledge = new EditorDropDown("Pledge");
addFieldToolPledge.Text = "Pledge";
addFieldToolPledge.ShowText = true;
addFieldToolPledge.ShowIcon = false;
PopulateFieldsTool(addFieldToolPledge, Constants.InteractionPledge);
mailMergeTools.Tools.Add(addFieldToolPledge);
EditorDropDown addFieldToolPayment =
new EditorDropDown("Payment");
addFieldToolPayment.Text = "Payment";
addFieldToolPayment.ShowText = true;
addFieldToolPayment.ShowIcon = false;
PopulateFieldsTool(addFieldToolPayment, Constants.InteractionPayment);
mailMergeTools.Tools.Add(addFieldToolPayment);
radtxtInteractionEmailMessage.Tools.Add(mailMergeTools);
RadEditorMailMerge.Tools.Add(mailMergeTools);
}
private void PopulateFieldsTool(EditorDropDown addFieldTool, Dictionary<int, string> InteractionLead)
{
string start = "{";
string end = "}";
foreach (var Dataitem in InteractionLead)
{
EditorDropDownItem item = new EditorDropDownItem();
item.Name =
Dataitem.Value;
item.Value = start +
Dataitem.Value + end;
addFieldTool.Items.Add(item);
}
}
public static Dictionary<int, string> InteractionGeneral = new Dictionary<int, string>()
{
{1,"Today's Date"},
{2,"Signature Image"},
{3,"Signature Name"},
{4,"Signature Designation"},
};
public static Dictionary<int, string>
InteractionLead = new Dictionary<int, string>()
{
{1,"Partner ID"},{2,"Lead ID"},{3,"First
Name"},{4,"Last Name"},{5,"Salutation"}, {6,"Mailing Address"},{8,"Address 1"},
{9,"Address 2"},{10,"Address 3"},{11,"City"},{12,"State"},{13,"Postal
Code"},
{14,"Country"},{15,"Job Title"},{16,"Phone No"},
{17,"Mobile"},{18,"Email"},{19,"PAN
Number"},
};
After this write your code for replacing
the merge fields with your code .
Example {Today's Date} to -- {date}