Occasionally, you will have a need to have a form element of one binder being bound to another data source. Sitefinity CMS client binders support nesting of For developers: Generic collection binder inside of other binders and in this article we will demonstrate how to nest a bound SELECT element, bound RADIO list and bound CHECKBOX list.
Before We start, though, let us take a look at the following screenshots to visualize the task that we wish to accomplish.
<
div
id
=
"storeForm"
runat
=
"server"
>
</
div
>
<
sitefinity:FormBinder
ID
=
"formBinder"
runat
=
"server"
ServiceUrl
=
"~/Sitefinity/Services/Commerce/Stores.svc"
TargetId
=
"storeForm"
OnClientBinderInitialized
=
"FormBinderInitialized"
OnClientItemDataBound
=
"FormItemDataBound"
DataKeyNames
=
"Id"
DataMembers
=
"Name, Description, ManagerName"
>
<
Containers
>
<
sitefinity:BinderContainer
runat
=
"server"
>
<
fieldset
>
<
legend
>Store info:</
legend
>
<
label
for
=
"Name"
>Store name:</
label
>
<
br
/>
<
input
id
=
"Name"
type
=
"text"
value
=
"{{Name}}"
/>
<
br
/>
<
label
for
=
"Description"
>Store description:</
label
>
<
br
/>
<
textarea
id
=
"Description"
rows
=
"5"
>{{Description}}</
textarea
>
<
br
/>
<
label
for
=
"ManagerName"
>Manager name:</
label
>
<
br
/>
<
select
id
=
"ManagerName"
class
=
"optionList"
></
select
>
<
br
/>
<
input
type
=
"button"
value
=
"Save"
sys:onclick
=
"SaveStore();"
/>
or
<
a
sys:href
=
"#"
sys:onclick
=
"CancelStore();"
>Cancel</
a
>
</
fieldset
>
</
sitefinity:BinderContainer
>
</
Containers
>
</
sitefinity:FormBinder
>
The ItemEventArgs object passed to us in this function eases the whole process quite a lot. Let us examine this code line by line:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StoresDropDown.aspx.cs" Inherits="StoresDropDown" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sitefinity" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
xmlns:sys
=
"javascript:Sys"
xmlns:dataview
=
"javascript:Sys.UI.DataView"
sys:activate
=
"*"
xmlns:code
=
"http://schemas.microsoft.com/aspnet/code "
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
ID
=
"scriptManager1"
runat
=
"server"
>
<
Scripts
>
<
asp:ScriptReference
Name
=
"MicrosoftAjax.js"
Path
=
"~/Sitefinity/Scripts/MicrosoftAjax.js"
/>
<
asp:ScriptReference
ScriptMode
=
"Inherit"
Path
=
"~/Sitefinity/Scripts/MicrosoftAjaxTemplates.js"
/>
<
asp:ScriptReference
ScriptMode
=
"Inherit"
Path
=
"~/Sitefinity/Scripts/MicrosoftAjaxAdoNet.js"
/>
</
Scripts
>
</
asp:ScriptManager
>
<
h2
>
Stores drop down
</
h2
>
<
a
href
=
"Employees.aspx"
>Employees</
a
>
|
<
strong
>Stores drop down</
strong
>
|
<
a
href
=
"StoresCheckboxes.aspx"
>Stores checkboxes</
a
>
|
<
a
href
=
"StoresRadioButtons.aspx"
>Stores radiobuttons</
a
>
<
hr
/>
<
input
id
=
"NewStoreButton"
type
=
"button"
value
=
"New store"
onclick
=
"NewStore();"
/>
<
div
id
=
"storeForm"
runat
=
"server"
>
</
div
>
<
telerik:RadGrid
ID
=
"storesGrid"
runat
=
"server"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"BinderContainer0"
></
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"BinderContainer1"
></
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"BinderContainer2"
></
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"BinderContainer3"
></
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
sitefinity:FormBinder
ID
=
"formBinder"
runat
=
"server"
ServiceUrl
=
"~/Sitefinity/Services/Commerce/Stores.svc"
TargetId
=
"storeForm"
OnClientBinderInitialized
=
"FormBinderInitialized"
OnClientItemDataBound
=
"FormItemDataBound"
DataKeyNames
=
"Id"
DataMembers
=
"Name, Description, ManagerName"
>
<
Containers
>
<
sitefinity:BinderContainer
runat
=
"server"
>
<
fieldset
>
<
legend
>Store info:</
legend
>
<
label
for
=
"Name"
>Store name:</
label
>
<
br
/>
<
input
id
=
"Name"
type
=
"text"
value
=
"{{Name}}"
/>
<
br
/>
<
label
for
=
"Description"
>Store description:</
label
>
<
br
/>
<
textarea
id
=
"Description"
rows
=
"5"
>{{Description}}</
textarea
>
<
br
/>
<
label
for
=
"ManagerName"
>Manager name:</
label
>
<
br
/>
<
select
id
=
"ManagerName"
class
=
"optionList"
></
select
>
<
br
/>
<
input
type
=
"button"
value
=
"Save"
sys:onclick
=
"SaveStore();"
/>
or
<
a
sys:href
=
"#"
sys:onclick
=
"CancelStore();"
>Cancel</
a
>
</
fieldset
>
</
sitefinity:BinderContainer
>
</
Containers
>
</
sitefinity:FormBinder
>
<
sitefinity:RadGridBinder
ID
=
"gridBinder"
runat
=
"server"
ServiceUrl
=
"~/Sitefinity/Services/Commerce/Stores.svc"
TargetId
=
"storesGrid"
BindOnLoad
=
"true"
OnClientBinderInitialized
=
"GridBinderInitialized"
OnClientItemEditCommand
=
"GridEditCommand"
DataKeyNames
=
"Id"
DataMembers
=
"Name, Description, ManagerName"
>
<
Containers
>
<
sitefinity:BinderContainer
runat
=
"server"
>
<
input
type
=
"button"
value
=
"Edit"
class
=
"editCommand"
/>
</
sitefinity:BinderContainer
>
<
sitefinity:BinderContainer
runat
=
"server"
>
{{Name}}
</
sitefinity:BinderContainer
>
<
sitefinity:BinderContainer
runat
=
"server"
>
{{Description}}
</
sitefinity:BinderContainer
>
<
sitefinity:BinderContainer
runat
=
"server"
>
{{ManagerName}}
</
sitefinity:BinderContainer
>
</
Containers
>
</
sitefinity:RadGridBinder
>
<
sitefinity:GenericCollectionBinder
ID
=
"employeesBinder"
runat
=
"server"
ServiceUrl
=
"~/Sitefinity/Services/Commerce/Employees.svc"
OnClientBinderInitialized
=
"EmployeesBinderInitialized"
DataKeyNames
=
"Id"
DataMembers
=
"Name"
>
<
Containers
>
<
sitefinity:BinderContainer
runat
=
"server"
RenderContainer
=
"false"
TemplateHolderTag
=
"Select"
>
<
option
value
=
"{{Name}}"
>{{Name}}</
option
>
</
sitefinity:BinderContainer
>
</
Containers
>
</
sitefinity:GenericCollectionBinder
>
<
script
type
=
"text/javascript"
>
var formBinder;
var gridBinder;
var employeesBinder;
function FormBinderInitialized(sender, args) {
formBinder = sender;
formBinder.AddValidationRule('Name', 'required', 'Name is a required field');
}
function GridBinderInitialized(sender, args) {
gridBinder = sender;
}
function EmployeesBinderInitialized(sender, args) {
employeesBinder = sender;
}
function NewStore() {
formBinder.New();
formBinder.get_globalDataKeys()["Id"] = formBinder.GetEmptyGuid();
}
function SaveStore() {
if (formBinder.SaveChanges()) {
formBinder.ClearTarget();
gridBinder.DataBind();
}
}
function CancelStore() {
formBinder.ClearTarget();
return false;
}
function GridEditCommand(sender, args) {
formBinder.get_globalDataKeys()["Id"] = args.get_key()["Id"];
formBinder.DataBind();
}
function FormItemDataBound(sender, args) {
var target = args.FindControl('ManagerName');
if (args.get_dataItem()) {
employeesBinder.set_selectedValue(args.get_dataItem().ManagerName);
}
employeesBinder.set_target(target);
employeesBinder.DataBind();
}
</
script
>
</
body
>
</
html
>