I need to bind dynamic controls in Grid column.
Ex.
I have two Columns. first column as displaying Text from Data Table.
Second column load controls from data table.
In DataTable having type of data type like Drop down,combo box, radio, check box. Text Box etc.
First Row Bind Combo box,
Second row Bind as Radio
Third Row bind as Text box, etc.
8 Answers, 1 is accepted
Any one can look up this issue.
You should set the template of your column:
columns.Bound(o => o.Type).Template(o =>
{
%>
<% if (o.Type == "textbox") { %>
<%= Html.TextBox() %>
<% } else if (o.Type == "dropdown") { %>
<%= Html.DropDownList() %>
<% } %>
<%
});
Atanas Korchev
the Telerik team
I've trouble in implementing your code. Below is my code to bind in the grid:
@(Html.Telerik().Grid<HomeFrontCRM.Web.UI.Models.MyModels>().Name("SelectionGrid").DataKeys(dataKeys => dataKeys.Add(o => o.Description)).ToolBar(commands =>
{
commands.SubmitChanges().ButtonType(GridButtonType.Image);}).DataBinding(dataBinding => dataBinding.Ajax()
.Select(
"Select", "Controller")
.Update(
"Save", "Controller")).Columns(columns =>
{
columns.Bound(o => o.Description)
columns.Bound(o => o.Qty).Title("Dynamic Control").ClientTemplate("<strong>Dynamic<strong>").Template(o =>
{
if (o.Qty == 1)
{
Html.DropDownList("asdasdasd");
}
else if (o.Qty != 1)
{
Html.TextBox("asd");
}}).Width(100);
I'm able to see only the text box, and not the Drop down list. I tried with combo also but didn't succeed
if possible, Can you send us any sample project
Basically the approach which Atanas showed you in Webforms syntax looks like this in Razor syntax:
columns.Bound(c => c.ContactName).Template(@<text> @if (item.Type=="TextBox")) { @Html.TextBox("textbox"+item.CustomerID, item.ContactName) } else { @Html.Telerik().Editor().Name("editor"+item.CustomerID).Value(item.ContactName) } </text>);Regards,
Petur Subev
the Telerik team
None of the code helps me to succeed in my attempt. I'd very much appreciate, if I get this done in my InCell/Inline editing grid. Can anyone provide me a working sample.
Please find in the attached files a sample project implementing the approach from my previous post.
I hope this helps.
Greetings,
Petur Subev
the Telerik team