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

Modify edit template at runtime and interact with other edit controls

3 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 18 Dec 2012, 11:02 PM
I am currently binding a dynamic datasource to a grid and due to this I can't define my edit template at design time. Using the bottom data row in the attached image (the result set from SQL) I would want to put the row in to edit mode and make BHP_Vehicle a dropdown with a number of options and BodyStyle_Vehicle a dropdown with a different set of options.  I have the datasource in memory so can get the dropdown options based on the column name and rows primary key but I don't know how I can access/control the template when the row is switched in to edit mode.

Further to this, while the row is in edit mode, if a selection is made in the BHP_Vehicle column I would want to rebind the BodyStyle_Vehicle dropdown and vice versa.  Hope this makes sense but does anybody know whether this is possible with the Telerik grid and if so the best way to approach it.

Thanks for your help!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Dec 2012, 04:11 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       DropDownList ddl = (DropDownList)sender;
       GridEditableItem item = (GridEditableItem)ddl.NamingContainer;
       DropDownList ddl2 = (DropDownList)item.FindControl("DropDownList2");
   }

Thanks,
Shinu.
0
Richard
Top achievements
Rank 1
answered on 19 Dec 2012, 07:41 AM
Thanks Shinu, I can see that will help me with the second part but how do I get that dropdownlist in the edit template when I can't define the template at design time?

Thanks
0
Shinu
Top achievements
Rank 2
answered on 20 Dec 2012, 05:27 AM
Hi,

When creating a grid dynamically that contains a template column, you must create the templates dynamically in the code-behind and assign them to the ItemTemplate and EditItemTemplate properties of the column. To create a template dynamically, you must define a custom class that implements the ITemplate interface. Then you can assign an instance of this class to the ItemTemplate or EditTemplateTemplate property of the GridTemplateColumn object.
C#:
public class RadGridEditTemplate : ITemplate
{
         protected DropDownList ddl;
        
}
public void InstantiateIn(System.Web.UI.Control container)
{
            DropDownList ddl = new DropDownList();
            ddl.ID = "dd11";
            container.Controls.Add(ddl);
}
protected void Page_Init(object sender, EventArgs e)
 NewTemplateColumn templateColumn = new NewTemplateColumn();
 grid.MasterTableView.Columns.Add(templateColumn);
 templateColumn.EditItemTemplate = new TemplateColumn();
}

Thanks,
Shinu.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Richard
Top achievements
Rank 1
Share this question
or