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

[Solved] Conditional expression in Pop up Grid Editor?

1 Answer 18 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.
Joshua Deye
Top achievements
Rank 1
Joshua Deye asked on 10 Nov 2011, 08:56 PM
I'm using the Telerik MVC extensions (version 2011.2.712.340).  I have a page with a grid to manage Contacts on it that uses a UserControl for the Editor. 

I've got it working, but I wanted to add some functionality that would allow the user to select a past Contact from their history.  I can't seem to figure out how to access the data of the model passed to the User Control. 

Here's what I currently have:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DART.Models.Contact>" %>
<% =Html.Hidden("ContactID") %>
  
  
<div class="CoverSheetFormatting Instruction" style="width:550px;">
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Title:   </div>
        <div class="CoverSheetData"><%= Html.DropDownList("TitleID", (List<SelectListItem>)(ViewData["TitleList"]))%></div>
    </div>
    <div style='clear: both;'></div>
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Contact Type:   </div>
        <div class="CoverSheetData"><%= Html.DropDownList("ContactTypeID", (List<SelectListItem>)(ViewData["ContactTypeList"]))%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">First Name:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("FirstName")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Last Name:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("LastName")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Email:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("Email")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Phone:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("Phone")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Fax:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("Fax")%></div>
    </div>        
</div>


I'd like to end up with a conditional drop down at the top that would appear if it is an insert, but disappear if it is an edit of an existing contact.  The code would look something like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DART.Models.Contact>" %>
<% =Html.Hidden("ContactID") %>
  
  
<div class="CoverSheetFormatting Instruction" style="width:550px;">
<%  if(Model.ContactID == 0) {%>
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Past Contact:</div>
        <div class="CoverSheetData"><%= Html.DropDownList("ContactID", (List<SelectListItem>)(ViewData["MrPastContacts"]))%></div>
    </div>
<%}%>
  
  
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Title:   </div>
        <div class="CoverSheetData"><%= Html.DropDownList("TitleID", (List<SelectListItem>)(ViewData["TitleList"]))%></div>
    </div>
    <div style='clear: both;'></div>
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Contact Type:   </div>
        <div class="CoverSheetData"><%= Html.DropDownList("ContactTypeID", (List<SelectListItem>)(ViewData["ContactTypeList"]))%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">First Name:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("FirstName")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Last Name:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("LastName")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Email:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("Email")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Phone:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("Phone")%></div>
    </div>        
    <div style="display:table-row;">
        <div class="CoverSheetLabel TableHeaderLabel">Fax:   </div>
        <div class="CoverSheetData"><%= Html.TextBox("Fax")%></div>
    </div>        
</div>

I've tried a number of different ways to access the data, but can't seem to find anything that will give the ID.  Any recommendations on the Syntax to get the value that is being passed?

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 11 Nov 2011, 08:57 AM
Hi Joshua Deye,

 If you are using server editing then the Model property should be what you need. The Model of the editor template partial view would contain the current model instance (edited grid record).

 If you are using Ajax editing you need to use JavaScript in order to hide different parts from the UI. The OnEdit event is designed to handle such cases.

Regards,
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
Tags
Grid
Asked by
Joshua Deye
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or