Hi Marie,
Currently, we do not provide support to generate check box
during data bind. However, this could be achieved by manually adding checkboxes
to the GenericDropdown. We have prepared a simple sample to exhibit the check
box list in Data bind and the sample can be downloaded from the link given
below,
In the
attached sample, we have dynamically added the checkboxes in the “ClientSideOnLoaded” event
as given in the below code snippet,
<code>
[View]
@{Html.Syncfusion().GenericDropDown("myGenericDropDown", new { style = "display:inline-block;"
})
.DataSource((System.Collections.IEnumerable)Model)
.BindTo(fields => fields
.Id("ToolbarItemId")
.Text("ToolbarItemText")
.ImageUrl("ImageUrl")
).AllowMultipleSelection(true)
.ClientSideOnClick("OnClick1").ClientSideOnLoaded("ClientSideOnLoaded")
.Render();
}
[Script]
function ClientSideOnLoaded(sender, args)
{
//Adding
checkbox dynamically to GDD control
$("#myGenericDropDown_DropDownContainer").find(".gddChildItem").each(function (i, item) {
var
html = '<input type="checkbox"
name="' + $(item).text() + '"
value="' + $(item).text() + '"
/>';
$(this).prepend(html);
});
}
</code>
Note: AllowMultipleSelection should
be enabled to allow multiple selection.
The values
of the checked items will be updated in the textbox using ClientAPI “setText” and this value can
be passed to controller during post by including the GenericDropDown control
inside Html.BeginForm. the retrieved values then splitted based on the
separators to get the selected items collection. Please refer the below code,
<code>
[Controller]
[HttpPost]
public ActionResult Index(string
myGenericDropDown)
{
//myGenericDropDown
refers the value in the Textbox then split it using separator to retrieve the
selected items collection
IList<string> selectedItems = myGenericDropDown.Split(';').ToList();
var
data = SqlCE.Flags;
return
View(data);
}
</code>
Kindly try the attached sample or modify your sample based
on the solution we provided and let us know if this helps.
Regards,
Varalakshmi