This is a migrated thread and some comments may be shown as answers.

[Solved] dynamic controls bind in Grid

8 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Daryl Shenner
Top achievements
Rank 1
Daryl Shenner asked on 22 May 2012, 06:20 AM
Hi,
    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

Sort by
0
Daryl Shenner
Top achievements
Rank 1
answered on 22 May 2012, 12:27 PM
Hi,

Any one can look up this issue.
0
Daryl Shenner
Top achievements
Rank 1
answered on 24 May 2012, 12:20 PM
Any one can look up this issue.
0
Daryl Shenner
Top achievements
Rank 1
answered on 25 May 2012, 05:18 AM
any body know this issue.
0
Atanas Korchev
Telerik team
answered on 25 May 2012, 08:17 AM
Hello,

 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() %>         
        <% } %>
   <%
});

All the best,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Daryl Shenner
Top achievements
Rank 1
answered on 28 May 2012, 07:02 AM
Hi ,

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
0
Petur Subev
Telerik team
answered on 29 May 2012, 01:05 PM
Hi Daryl,

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
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Daryl Shenner
Top achievements
Rank 1
answered on 30 May 2012, 07:03 AM
Hi Peter,

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.
0
Petur Subev
Telerik team
answered on 01 Jun 2012, 09:53 AM
Hello Daryl,

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
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Daryl Shenner
Top achievements
Rank 1
Answers by
Daryl Shenner
Top achievements
Rank 1
Atanas Korchev
Telerik team
Petur Subev
Telerik team
Share this question
or