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

[Solved] Conditional Editor Template

2 Answers 196 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.
Nick
Top achievements
Rank 1
Nick asked on 01 Aug 2011, 04:21 PM
I have a grid with  columns - Name, Value, Type.
If Type==1, then the I want the Editor for Value to be a TextBox.
If Type==2, then I need to display a dropdownlist. 
So far, I'm able to pass the Type to the Editor Template and load a dropdownlist with ajax.

What's the best way to handle this scenario?  Is there anyway to load a PartialView for the Edit Template in OnEdit of the Grid?
Can I have both dropdownlist and textbox in the EditorTemplate view and hide one/display the other base on Type?

Thanks,
nick


2 Answers, 1 is accepted

Sort by
0
Bogdan
Top achievements
Rank 1
answered on 17 Feb 2012, 11:25 PM
Have you found a solution to this ? I am facing the same issue.
0
Patrick
Top achievements
Rank 1
answered on 21 Feb 2012, 01:28 PM
I have a solution, but it's not great.
In the editor template (partial view using UIHint) for my column i have both a dropdownlist and a textbox.
I added an OnEdit eventhandler to the grid where i set a javascript variable to the Id of the row so i can use it in the editor template to load the ddl.  The ddl is loaded by adding an OnLoad eventhandler.  In OnEdit of the grid, if type==1 i hide the textbox, otherwise hide the ddl.
Works for me.  Good luck
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Bogdan
Top achievements
Rank 1
Patrick
Top achievements
Rank 1
Share this question
or