Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

GridView - How to specify an EditForm template only when adding a new row

$
0
0

This example illustrates how to specify a grid's EditForm template only when adding a new row and leave the default template when editing a row. Perform the following steps to accomplish this task:

1. Handle the MVCxClientGridView.BeginCallback event to determine which mode the grid will be in after a callback:

[JScript]
 function OnBeginCallback(s, e){var isNewRowNow = s.IsNewRowEditing();var isSwitchToNewRow = (e.command == 'ADDNEWROW');var IsCancelEdit = (e.command == 'CANCELEDIT');var IsSwitchToEdit = (e.command == 'STARTEDIT'); var result = (isSwitchToNewRow * !IsCancelEdit + isNewRowNow) * !IsSwitchToEdit; e.customArgs['IsNewRow'] = Boolean(result);}

2. Process the received value in the controller and pass it to the view using ViewBag:

[C#]
[HttpPost,ValidateInput(false)]publicActionResultGridViewEditingPartial(boolIsNewRow){if(IsNewRow) ViewBag.IsNewRow=true;returnPartialView(list.GetPersons());}[HttpPost,ValidateInput(false)]publicActionResultEditingAddNew([ModelBinder(typeof(DevExpressEditorsBinder))]Personperson){ViewBag.IsNewRow=true;...}

3. After that, you can create a template based on the ViewBag value:

[C#]
if(ViewBag.IsNewRow!=null)   if(ViewBag.IsNewRow==true)       settings.SetEditFormTemplateContent(c=>       {           ViewContext.Writer.Write("EditForm Template Content");       });

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>