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

Begin in edit

25 Answers 306 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 29 Oct 2014, 07:51 PM
How do you make a RadDataForm begin in edit mode on the initial get?

25 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 03 Nov 2014, 04:22 PM
Hi Kevin,

Thank you for getting back to us.

You can use the following approach to achieve the requested functionality:
protected void CandidateDataForm_PreRender(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // first approach
        RadDataFormItem item = CandidateDataForm.Items[0];
        item.FireCommandEvent("Edit", "");
 
        // second approach
        //(CandidateDataForm.Items[0] as RadDataFormDataItem).Edit = true;
        //CandidateDataForm.Rebind();
    }
}

Hope this helps.

Regards,
Eyup
Telerik
0
Kevin
Top achievements
Rank 1
answered on 04 Nov 2014, 08:23 PM
For me CandidateDataForm.Items.Count==0 in PreRender. I'm using a SqlDataSource if that makes a difference.
0
Eyup
Telerik team
answered on 07 Nov 2014, 12:36 PM
Hello Kevin,

This behavior is strange, indeed. Can you please prepare a very basic runnable web site sample demonstrating the problem and open a support ticket to send it to us. Thus, we will be able to further debug and analyze the project and try to determine the cause of the issue.

Regards,
Eyup
Telerik
0
Kevin
Top achievements
Rank 1
answered on 10 Nov 2014, 05:12 PM
I just wanted to make the note that it's important to do this in the DataForm's PreRender and not the Page's PreRender.

kd
0
Eyup
Telerik team
answered on 13 Nov 2014, 12:51 AM
Hi Kevin,

Thank you for sharing this note with our community. I hope it will be helpful to other developers as well.

Regards,
Eyup
Telerik
0
Bill Wolff
Top achievements
Rank 1
answered on 13 Nov 2014, 08:50 PM
This works fine for Edit mode. It will not work for Insert since there are no existing items. How would I open a dataform in Insert mode for the first record? This could be much simpler if there were a property on the RadDataForm that specifies which mode to open in: View, Edit, Insert. Right now, it defaults to View at Item[0].
0
Viktor Tachev
Telerik team
answered on 18 Nov 2014, 01:25 PM
Hi Bill,

If you would like to place the RadDataForm initially in Insert Mode you can use an approach similar to the one suggested by Eyup.

You can handle the PreRender event if the RadDataForm control and set the IsItemInserted property to true:

protected void RadDataForm1_PreRender(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        (sender as RadDataForm).IsItemInserted = true;
        (sender as RadDataForm).Rebind();
    }
}


Regards,
Viktor Tachev
Telerik
0
Mike
Top achievements
Rank 1
answered on 19 May 2015, 03:02 PM

I'm finding this, as well.

 

I have trying the posted "answer" in the prerender event of the raddataform and the items count is always 0

 

If I simply let the dataform load, it presents a record in the itemtemplate's "view' mode, so i know that my objectdatasouce is returning at least one record.

 

Any ideas why this is happening?

 

Mmike

0
Viktor Tachev
Telerik team
answered on 21 May 2015, 12:58 PM
Hello Mike,

Would you share the markup of the page with the related code-behind? This will give us better understanding of your scenario. Thus, we would be able to examine the code and look for what could cause the issue.

Regards,
Viktor Tachev
Telerik
0
Ole Oscar
Top achievements
Rank 1
answered on 27 Nov 2015, 01:05 PM
I had the same problem with the items collection always with no items. Then I added an empty <ItemTemplate> and then it worked.
0
Viktor Tachev
Telerik team
answered on 30 Nov 2015, 09:52 AM
Hi Ole,

Thank you for sharing your solution for the issue with the community. This can help someone facing similar behavior.


Regards,
Viktor Tachev
Telerik
0
jyotsna
Top achievements
Rank 1
answered on 17 Mar 2016, 06:14 PM

I am trying to open the Raddataform which is in Editform control in the insert mode ,and as there are no items in the grid it goes to exception  as above users,I tried the solution from Ole but dint work out. when I have data in the grid it works fine for the new grid to add a record using the dataform it fails.pls suggest.Here is sample.

 

gridDataform is the instance of the usercontrol which has Raddataform and this code is beign used in the grid itemcommand.

 

                    if (gridDataform == null)
                    { throw new Exception("No Grid Found"); }

                    log.logDebug(logMessage: "Fire Insert Mode for DataForm");


                   gridDataform.DataForm.Items[0].FireCommandEvent("InitInsert", "");

0
jyotsna
Top achievements
Rank 1
answered on 17 Mar 2016, 08:10 PM

Also my add buttons are on the mastertableview of the grid

 

 <MasterTableView Width="100%" CommandItemDisplay="Top" ShowGroupFooter="true" AllowFilteringByColumn="true">
            <EditFormSettings EditFormType="Template">
                <EditColumn UniqueName="EditCommandColumn1" />
                <FormTemplate>
                    <uc1:PageUIControl IsBoundToGrid="true" runat="server" ID="EditFormControl"  />
                </FormTemplate>
                <PopUpSettings ScrollBars="None" />
            </EditFormSettings>

            <CommandItemTemplate>


                <div style="color:black!important;" >

                    <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGridUI.EditIndexes.Count == 0 %>'><i class="fa fa-pencil fa-lg"></i></asp:LinkButton>
                        <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGridUI.EditIndexes.Count > 0 %>'><i class="fa fa-pencil fa-lg"></i></asp:LinkButton>
                        <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGridUI.EditIndexes.Count > 0 || RadGridUI.MasterTableView.IsItemInserted %>'><i class="fa fa-ban fa-lg"></i></asp:LinkButton>&nbsp;&nbsp;
                       <asp:LinkButton ID="btnNew" runat="server" CommandName="InitInsert" Visible='<%# !RadGridUI.MasterTableView.IsItemInserted %>'><i class="fa fa-plus-square fa-lg"></i></asp:LinkButton>
                        <asp:LinkButton ID="btnInsert" runat="server" CommandName="PerformInsert" Visible='<%# RadGridUI.MasterTableView.IsItemInserted %>'><i class="fa fa-plus-square fa-lg"></i></asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="btnDelete" OnClientClick="javascript:return confirm('Delete all selected customers?')" runat="server" CommandName="DeleteSelected"><i class="fa fa-trash fa-lg"></i></asp:LinkButton>&nbsp;&nbsp;

                </div>

            </CommandItemTemplate>
        </MasterTableView>

 

0
Viktor Tachev
Telerik team
answered on 21 Mar 2016, 01:18 PM
Hi,

Please examine the following online examples that illustrate how you can use Template EditForms and also UserControls as EditForm:



Regards,
Viktor Tachev
Telerik
0
jyotsna
Top achievements
Rank 1
answered on 21 Mar 2016, 08:01 PM

Victor,

I tried all the code as per your links before,and the thing is it is totally working to nsert if the items has data,for a new record I mean to say if You insert the first record and when you click on Add  in the Grid,it is not able to open the Raddataform in the Insert mode.

The Below code Perfectly works  if the datasource has Data,But to insert a first record it fails to open the raddataform in insert mode.

As there is no data this statement is going to exception.

gridDataform.DataForm.Items[0].FireCommandEvent("InitInsert", "");

I also tried many ways as suggested in the above forums,like rebinding ,setting the isinsertmode =true All these only work if thre is data.Please suggest.I hope you got my point.

Thanks in Advance

if (e.CommandName == RadGrid.InitInsertCommandName)


e.Canceled = true;
log.logDebug(logMessage: "Setup Dataform for Insert");

e.Item.OwnerTableView.InsertItem();

GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();

if (insertedItem == null)
 { throw new Exception("No Inserted Item Found"); }
 gridDataform = (PageUIControl)insertedItem.FindControl("EditFormControl");
 gridDataform.UpdateMode = PageUIControl.Mode.Insert; 
gridDataform.UserContext = this.UserContext;
 gridDataform.UserID = this.UserID; 
 // gridDataform = insertedItem.FindControl(MyUserControlId) as PageUIControl;
 if (gridDataform == null) { throw new Exception("No Grid Found"); }
 log.logDebug(logMessage: "Fire Insert Mode for DataForm"); 
gridDataform.DataForm.IsItemInserted = true;
 
gridDataform.DataForm.Items[0].FireCommandEvent("InitInsert", "");
 
} else if (e.CommandName == "RowClick") if (ItemCommand !=null) { ItemCommand(sender, e); } }

0
jyotsna
Top achievements
Rank 1
answered on 22 Mar 2016, 01:42 PM
My Issue is not witht the edit form  settings,My issue is with the raddataform not opening in Insert mode if no datasource  when it is in Editformsettings of a grid.
0
Vasil
Telerik team
answered on 24 Mar 2016, 12:46 PM
Hi Jyotsna,

What type is the collection that you are binding. We have recently fixed an issue with empty IQuerable
http://feedback.telerik.com/Project/108/Feedback/Details/181925-a-server-exception-is-thrown-when-trying-to-add-a-new-record-to-radgrid-which-is

For example this code is not working. But it will work in the next official version.

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = Enumerable.Empty<Thing>().AsQueryable();
}
The workaround is to bind directly to Enumerable.

If you still problem, please describe it in further details. I see from your code that you are using RadGrid and DataForm probably inside. But the exact configuration is not clear enough.

Regards,
Vasil
Telerik
0
jyotsna
Top achievements
Rank 1
answered on 24 Mar 2016, 01:41 PM

Its a directDataset  Binding,and on Edit/Insert from the Grid I am trying to open the Raddataform,Where it fails for Insert when inserting first record. 

protected void RadGridUI_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            logHelper log = null;
            HtmlTable layoutTable = null;
            HtmlGenericControl wrapper = null;
            TableRow layoutTableRow1 = null;
            TableRow layoutTableRow2 = null;
            TableCell vCell = null;
            TableCell vCell2 = null;
            ImageButton imageButton = null;
            Label vtitle = null;
            Control veditCtrl = null;
            EventHandler vevent = null;
            try
            {
                log = logHelper.getlogger(ref log, Logger: "RadGridUI_NeedDataSource", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "RadGridUI_NeedDataSource Start");

                if (IntitiateGridLoad)
                {
                    DataSet entityData = DynamicUILayoutHelper.FetchEntityData(EntityObject, selectedCommand: "[EIS_SP_GetGenericEntityData]", log: ref log, whereCond: WhereCond,mapperId:MapperID,taskOrder:TaskOrderID);
                log.logDebug(logMessage: "RadGridUI_NeedDataSource Fetched Data Done");
                RadGridUI.DataSource = entityData;
                    //if (entityData.Tables[0].Rows.Count > 0)
                    //    RadGridUI.Visible = true;
                    //else
                    //    RadGridUI.Visible = false;
                    if (entityData.Tables.Count > 1)
                    {
                        if (Convert.ToInt64(entityData.Tables[1].Rows[0]["Count"].ToString()) > 300000)
                        {
                            //((TextBox)TableUIErrorNotification.ContentContainer.FindControl("txtnot")).Text = "Entity has more than 300000 records .Please apply filter to get selected load";
                            //TableUIErrorNotification.Show();
                        }

                    }

                 }

                else
                    RadGridUI.DataSource = null;



            log.logDebug(logMessage: "RadGridUI_NeedDataSource ListView DataSource Setup Done");

            }
            catch (Exception ex)
            {
                log.logError(logMessage: "RadGridUI_NeedDataSource Error: " + ex.Message);
                ((TextBox)TableUIErrorNotification.ContentContainer.FindControl("txtnot")).Text = log.logstr;
                TableUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "RadGridUI_NeedDataSource Exit ");
                log.Flush(logger: "RadGridUI_NeedDataSource");
            }
        }

0
Vasil
Telerik team
answered on 25 Mar 2016, 08:42 AM
Hi Jyotsna,

I am not seeing the code for creating using the DataForm in your page. I would suggest you to check this example, and if you continue to have the problem, please send us whole example, where we can test/debug what you are having.

Regards,
Vasil
Telerik
0
jyotsna
Top achievements
Rank 1
answered on 25 Mar 2016, 02:06 PM

hi Vasil,

here the usercontrol with the dataform:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PageUIControl.ascx.cs" Inherits="BMA.Core_User_Controls.PageUIControl" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<telerik:RadAjaxManagerProxy ID="RadAjaxManager1" runat="server" ClientIDMode="AutoID">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Raddataform1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Raddataform1" LoadingPanelID="PageUIPnlLoad"></telerik:AjaxUpdatedControl>
                <telerik:AjaxUpdatedControl ControlID="PageUIErrorNotification" LoadingPanelID="PageUIPnlLoad"> </telerik:AjaxUpdatedControl>  <telerik:AjaxUpdatedControl ControlID="ValidationSummary1" LoadingPanelID="PageUIPnlLoad">
                </telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>
<link href="../Content/styles.css" rel="stylesheet" />


<div id="divPageUIControlMain">


    <asp:Panel ID="Panel1" runat="server" Width="100%" BorderStyle="None" CssClass="PageUIBackground">
        <telerik:RadAjaxLoadingPanel runat="server" ID="PageUIPnlLoad" Skin="Metro" Transparency="35">
                     <div style="background-color:#ffffff; width:100%; height:100%"></div>
                    </telerik:RadAjaxLoadingPanel>  
        <telerik:RadNotification ID="PageUIErrorNotification" runat="server" EnableRoundedCorners="true"
        EnableShadow="true" Text="" Title="" Animation="Slide" AnimationDuration="800" Position="TopCenter" ContentScrolling="Auto">
                <ContentTemplate>
                    <b>Please copy the Log below and send to Support Team for Issue Resolution </b>
                    <br>
                    <asp:TextBox TextMode="MultiLine" ID="txtpageui" Enabled="false" Height="130" Width="580" runat="server"></asp:TextBox>
                </ContentTemplate> 
               </telerik:RadNotification>
               <telerik:RadDataForm Visible="true" runat="server" ID="Raddataform1" AllowPaging="True" EnableViewState="true"  OnNeedDataSource="Raddataform1_NeedDataSource" BorderStyle="None" 
                   OnItemUpdating="RadDataForm1_ItemUpdating" OnItemCanceling="Raddataform1_ItemCanceling"  OnItemInserting="RadDataForm1_ItemInserting" >
                    </telerik:RadDataForm>

 
    <asp:ValidationSummary ID="ValidationSummary1" runat="server"  ShowMessageBox="false"  ShowSummary="true" ShowValidationErrors="true"    />
    </asp:Panel>
</div>

Code behind:

using BMA.Helper;
using System;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Telerik.Web;
using Telerik.Web.UI;



namespace BMA.Core_User_Controls
{
    public partial class PageUIControl : System.Web.UI.UserControl
    {
        public string UserID
        {
            get
            {

                return Session["UserID"].ToString();
            }
            set
            {
                Session["UserID"] = value;
            }
        }
    

        public UserContextHelper UserContext
        {
            get
            {
                return (UserContextHelper)Session["UserContext"];
            }
            set
            {
                Session["UserContext"] = value;
            }
        }
        public RadDataForm DataForm
        {
            get
            {
                return Raddataform1;
            }
        }
        public string KeyNameValue
        {
            get
            {
                return ViewState["PageUIKeyName"].ToString();
            }
            set
            {
                ViewState["PageUIKeyName"] = value;
            }
        }

        

        public string EntityObject
        {
            get
            {
                if (ViewState["PageUIEntityObject"] == null)
                { ViewState["PageUIEntityObject"] = ""; }
                return ViewState["PageUIEntityObject"].ToString();
            }
            set
            {
                ViewState["PageUIEntityObject"] = value;
            }
        }

        public Mode UpdateMode
        {
            get
            {
                if (ViewState["PageUIUpdateMode"] == null)
                { ViewState["PageUIUpdateMode"] = Mode.Item; }
                return (Mode)ViewState["PageUIUpdateMode"];
            }
            set
            {
                ViewState["PageUIUpdateMode"] = value;
            }
        }
        public enum Mode
        {
            Update,
            Insert,
            Item
        }

        public string Entity
        {
            get
            {
                if (ViewState["PageUIEntity"] == null)
                { ViewState["PageUIEntity"] = ""; }
                return ViewState["PageUIEntity"].ToString();
            }
            set
            {
                ViewState["PageUIEntity"] = value;
            }
        }
        private string _primaryKeyValue;
        public event EventHandler ItemCommand;

      
        public int GridItemIndex
        {
            set
            {
                ViewState["PageUIGridItemIndex"] = value;

            }
            get
            {
                if (ViewState["PageUIGridItemIndex"] == null)
                { ViewState["PageUIGridItemIndex"] = -1; }

                return (int)ViewState["PageUIGridItemIndex"];
            }
        }

        public bool IsBoundToGrid
        {
            set
            {
                ViewState["PageUIIsBoundToGrid"] = value;

            }
            get
            {
                if (ViewState["PageUIIsBoundToGrid"] == null)
                { ViewState["PageUIIsBoundToGrid"] = false; }

                return (bool)ViewState["PageUIIsBoundToGrid"];
            }
        }
        public int TaskOrderID
        {
            get
            {
                if (ViewState["PageUITaskOrderID"] == null)
                {
                    if (ViewState["PageUITaskOrderID"] == null)
                        ViewState["PageUITaskOrderID"] = 0;
                }
                return (int)ViewState["PageUITaskOrderID"];
            }
            set
            {
                ViewState["TableUITaskOrderID"] = value;
            }
        }
        public string PrimaryKeyValue
        {
            get
            {

                return (string)ViewState["PageUIprimaryKeyValue"];
            }
            set
            {
               ViewState["PageUIprimaryKeyValue"] = value;
            }
        }
        public string PrimaryKeyValueData
        {
            get
            {

                return (string)ViewState["PageUIPrimaryKeyValueData"];
            }
            set
            {
                ViewState["PageUIPrimaryKeyValueData"] = value;
            }
        }
        
        public int columnsno
        {
            get
            {
                if (ViewState["PageUIcolumnsno"] == null)
                { ViewState["PageUIcolumnsno"] = 5; }

                return (int)ViewState["PageUIcolumnsno"];
            }
            set
            {
                ViewState["PageUIcolumnsno"] = value;
            }
        }

        public string Validationgroup
        {
            get
            {
                return (String)ViewState["Validationgroup"];
            }
            set
            {
                ViewState["Validationgroup"] = value;
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {

            logHelper log = null;
            try
            {

                log = logHelper.getlogger(ref log, Logger: "PageUI.Page_Init", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "Page_Init Start");

                if (!Page.IsPostBack)
                {

                    CurrentSkin = "Metro";
                }
                
                if (IsBoundToGrid)
                {
                    GridEditFormItem item = (GridEditFormItem)this.NamingContainer;
                    EntityTableUIControl TableCtl = (EntityTableUIControl)item.OwnerTableView.Parent.Parent.Parent;
                     // EntityTableUIControl TableCtl = (EntityTableUIControl)item.OwnerTableView.Parent;
                   // EntityTableUIControl TableCtl = (EntityTableUIControl)item.FindControl("EntityTableUIControl");
                    EntityObject = TableCtl.EntityObject;
                    Entity = TableCtl.Entity;

                        PrimaryKeyValue = TableCtl.PrimaryKeyValue;
                 
                    PrimaryKeyValueData = TableCtl.PrimaryKeyValueData;
                    if (PrimaryKeyValueData == "")
                        PrimaryKeyValueData = null;
                    
                        ValidationSummary1.ValidationGroup = TableCtl.Validationgroup;
                    Raddataform1.ValidationSettings.ValidationGroup = TableCtl.Validationgroup;
                    columnsno = TableCtl.columnsno;
                   
                }
                else
                {
                    string keydata = Request.QueryString["PrimaryKeyData"];
                    PrimaryKeyValueData = keydata;//"5539";

                   Entity = Request.QueryString["Entity"];
                    EntityObject = Request.QueryString["EntityObject"];
                    UserID = this.UserID;//Request.QueryString["UserID"];
                    
                }
                Raddataform1.Attributes["Updating"] = "false";
                
              //  Raddataform1.Attributes["Inserting"] = "false";
                log.logDebug(logMessage: "PageUI.Page_Init Executing RenderTableUITemplates Start");

                RenderTableUITemplates(uiEntity: Entity, log: ref log);

               // Notification.Title = Entity + " Table UI Notifications";
                //}

            }
            catch (Exception ex)
            {

                log.logError(logMessage: "PageUI.Page_Init Error: " + ex.Message);
                //throw ex;
                ((TextBox)PageUIErrorNotification.ContentContainer.FindControl("txtpageui")).Text = log.logstr;
                PageUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "Page_Init Exit ");
                log.Flush(logger: "PageUI.Page_Init");
            }

        }

        private void LayOutprerender_event(object sender, EventArgs e)
        {

        }
        public string CurrentSkin
        {
            get
            {

                return Session["CurrentSkin"].ToString();
            }
            set
            {

                Session["CurrentSkin"] = value;
            }
        }

        //public RadNotification Notification
        //{
        //    get
        //    {

        //        return (RadNotification)Session["Notification"];
        //    }
        //    set
        //    {

        //        Session["Notification"] = value;
        //    }
        //}


        public void RenderTableUITemplates(string uiEntity, ref logHelper log)
        {

            try
            {

                DataSet entityMetaData = null;
                // int columnsno = 4;

                log = logHelper.getlogger(ref log, Logger: "RenderPageUITemplates", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "RenderPageUITemplates Start uiEntity: " + "Entityttribute");

                entityMetaData = DynamicUILayoutHelper.FetchEntityMetaData(uiEntity, ref log);
                foreach (DataRow rowitem in entityMetaData.Tables[1].Rows)
                {
                    if (rowitem["Access"].ToString().IndexOf("R") > -1)
                    {
                        Raddataform1.Visible = true;
                        break;
                    }
                    else
                        Raddataform1.Visible = false;

                }
                log.logDebug(logMessage: "RenderPageUITemplates Creating Templates");

                KeyNameValue = DynamicUILayoutHelper.DataformKey(ref log, Entity, ref Raddataform1);
                ////Locate the changed row in the DataSource

                Raddataform1.DataKeyNames = new string[] { KeyNameValue };
                Raddataform1.LayoutTemplate = null;
             Raddataform1.EmptyDataTemplate = new PageUIEmptyDataTemplate(entityMetaData, log, CurrentSkin, new System.EventHandler(LayOutprerender_event));
                Raddataform1.EditItemTemplate = new PageUIEditItemTemplate(entityMetaData, log, columnsno);
                Raddataform1.ItemTemplate = new PageUIItemTemplate(entityMetaData, log, columnsno);
                Raddataform1.InsertItemTemplate = new PageUIInsertItemTemplate(entityMetaData, log, columnsno);

                log.logDebug(logMessage: "RenderPageUITemplates Templates Done");

                PageUIErrorNotification.Title = "PageUI :" + Entity + "  Page UI Notifications";
                
            }
            catch (Exception ex)
            {
                log.logError(logMessage: "RenderPageUITemplates Error: " + ex.Message);
                //Notification.Title = "PageUI" + "RenderPageUITemplates Error: " + ex.Message;
                // throw ex;
                ((TextBox)PageUIErrorNotification.ContentContainer.FindControl("txtpageui")).Text = log.logstr;
                PageUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "RenderPageUITemplates Exit ");
                log.Flush(logger: "RenderPageUITemplates");
            }
            

        }
        protected void Raddataform1_NeedDataSource(object sender, RadDataFormNeedDataSourceEventArgs e)
        {
            logHelper log = null;
            try
            {
                log = logHelper.getlogger(ref log, Logger: "Raddataform1_NeedDataSource", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "Raddataform1_NeedDataSource Start");
                if (Entity != "")
                {
                  DataSet entityData = DynamicUILayoutHelper.FetchEntityData(EntityObject, selectedCommand: "[EIS_SP_GetGenericEntityData]", log: ref log, primaryVal: PrimaryKeyValueData,taskOrder:TaskOrderID);
                   
                    log.logDebug(logMessage: "Raddataform1_NeedDataSource Fetched Data Done");

                    Raddataform1.DataSource = entityData;
                    if (entityData.Tables[0].Rows.Count > 0)
                        Raddataform1.Visible = true;
                    else
                        Raddataform1.Visible = false;

                    log.logDebug(logMessage: "Raddataform1_NeedDataSource RadDataform DataSource Setdate Done");
                }

            }
            catch (Exception ex)
            {
                log.logError(logMessage: "Raddataform1_NeedDataSource Error: " + ex.Message);
                //throw ex;
                ((TextBox)PageUIErrorNotification.ContentContainer.FindControl("txtpageui")).Text = log.logstr;
                PageUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "Raddataform1_NeedDataSource Exit ");
                log.Flush(logger: "Raddataform1_NeedDataSource");
            }

        }
        protected void RadDataForm1_ItemInserting(object sender, RadDataFormCommandEventArgs e)
        {
            logHelper log = null;
            try
            {
                log = logHelper.getlogger(ref log, Logger: "RadDataForm1_ItemInserting", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "RadDataForm1_ItemInserting Start");

                RadDataFormEditableItem editedItem = e.DataFormItem as RadDataFormEditableItem;


                Hashtable newValues = new Hashtable();
             //   Raddataform1.Attributes["Inserting"] = "True";
                editedItem.ExtractValues(newValues);

                string Rowkey = "";
                newValues.Add("UserName", UserID);
               // newValues.Add("TaskOrderID", TaskOrderID);
                newValues.Add("InsertMode", "I");
                
                //  object dit = editedItem.GetDataKeyValue(KeyNameValue);
                log = logHelper.getlogger(ref log, Logger: "RadDataForm1_ItemInserting" + "NewValues:" +newValues);
                DynamicUILayoutHelper.InsertEntityData(Entity, ref log, Rowkey, newValues);
                //Raddataform1.Attributes["Inserting"] = "false";
                if (IsBoundToGrid)
                {

                    GridEditFormItem item = (GridEditFormItem)this.NamingContainer;
                    EntityTableUIControl parentgrid = (EntityTableUIControl)item.OwnerTableView.Parent.Parent.Parent;
                    // EntityTableUIControl parentgrid = (EntityTableUIControl)editedItem.Page.FindControl("RadGridUI");
                    if (parentgrid != null)
                    {
                        parentgrid.Grid.MasterTableView.GetInsertItem().FireCommandEvent("Cancel", "");
                    }
                }


            }
            catch (Exception ex)
            {
                log.logError(logMessage: "RadDataForm1_ItemInserting Error: " + ex.Message);
                // throw ex;
                ((TextBox)PageUIErrorNotification.ContentContainer.FindControl("txtpageui")).Text = log.logstr;
                PageUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "RadDataForm1_ItemInserting Exit ");
                log.Flush(logger: "RadDataForm1_ItemInserting");
            }
        }
        protected void RadDataForm1_ItemUpdating(object sender, RadDataFormCommandEventArgs e)

        {
            logHelper log = null;
            try
            {
                log = logHelper.getlogger(ref log, Logger: "RadDataForm1_ItemUpdating", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "RadDataForm1_ItemUpdating Start");

                RadDataFormEditableItem editedItem = e.DataFormItem as RadDataFormEditableItem;

                Hashtable newValues = new Hashtable();
                Raddataform1.Attributes["Updating"] = "true";
                editedItem.ExtractValues(newValues);

                newValues.Add("UserName", UserID);
               // newValues.Add("TaskOrderID", TaskOrderID);
                newValues.Add("UpdateMode", "U");

                object dit = editedItem.GetDataKeyValue(KeyNameValue);
                log = logHelper.getlogger(ref log, Logger: "RadDataForm1_GetValues");
                log.logDebug(logMessage: "RadDataForm1_NewValues"+ "NewValues: " + newValues.Count);
                DynamicUILayoutHelper.UpdateEntityData(Entity, ref log, dit.ToString(), newValues);
                Raddataform1.Attributes["Updating"] = "false";
                if (IsBoundToGrid)
                {

                    GridEditFormItem item = (GridEditFormItem)this.NamingContainer;
                   // EntityTableUIControl parentgrid = (EntityTableUIControl)item.OwnerTableView.Parent.Parent.Parent;
                    EntityTableUIControl parentgrid = (EntityTableUIControl)item.OwnerTableView.Parent.Parent.Parent;
                    // EntityTableUIControl parentgrid = (EntityTableUIControl)editedItem.Page.FindControl("RadGridUI");
                    if (parentgrid == null)
                    { throw new Exception("Parent Grid Not Found!"); }

                    if (UpdateMode == Mode.Update)
                    {
                        if (GridItemIndex != -1)
                        {
                            if (parentgrid.Grid.Items[GridItemIndex] != null)
                            { parentgrid.Grid.Items[GridItemIndex].FireCommandEvent("Cancel", ""); }

                        }
                    }
                    else if (UpdateMode == Mode.Insert)
                    {

                        if (parentgrid.MasterTable.IsItemInserted)
                        {
                            parentgrid.Grid.MasterTableView.GetInsertItem().FireCommandEvent("Cancel", "");
                        }

                    }
                }

            }
            catch (Exception ex)
            {
                log.logError(logMessage: "RadDataForm1_ItemUpdating Error: " + ex.Message);
                // throw ex;
                ((TextBox)PageUIErrorNotification.ContentContainer.FindControl("txtpageui")).Text = log.logstr;
                PageUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "RadDataForm1_ItemUpdating Exit ");
                log.Flush(logger: "RadDataForm1_ItemUpdating");
            }


        }

        protected void Raddataform1_ItemCanceling(object sender, RadDataFormCommandEventArgs e)
        {
            logHelper log = null;
            try
            {
                log = logHelper.getlogger(ref log, Logger: "Raddataform1_ItemCanceling", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "Raddataform1_ItemCanceling Start");

                RadDataFormEditableItem editedItem = e.DataFormItem as RadDataFormEditableItem;


                if (IsBoundToGrid)
                {
                    GridEditFormItem item = (GridEditFormItem)this.NamingContainer;
                    // EntityTableUIControl parentgrid = (EntityTableUIControl)editedItem.Page.FindControl("RadGridUI");
                    EntityTableUIControl parentgrid = (EntityTableUIControl)item.OwnerTableView.Parent.Parent.Parent;
                    if (parentgrid == null)
                    { throw new Exception("Parent Grid Not Found!"); }

                    if (UpdateMode == Mode.Update)
                    {
                        if (GridItemIndex != -1)
                        {
                            if (parentgrid.Grid.Items[GridItemIndex] != null)
                            { parentgrid.Grid.Items[GridItemIndex].FireCommandEvent("Cancel", ""); }

                        }
                    }
                    else if (UpdateMode == Mode.Insert)
                    {

                        if (parentgrid.MasterTable.IsItemInserted)
                        {
                            parentgrid.Grid.MasterTableView.GetInsertItem().FireCommandEvent("Cancel", "");
                        }

                    }
                }

            }
            catch (Exception ex)
            {
                log.logError(logMessage: "Raddataform1_ItemCanceling Error: " + ex.Message);
                //throw ex;
                ((TextBox)PageUIErrorNotification.ContentContainer.FindControl("txtpageui")).Text = log.logstr;
                PageUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "Raddataform1_ItemCanceling Exit ");
                log.Flush(logger: "Raddataform1_ItemCanceling");
            }
        }
    }


}

Grids UI where Raddataform is used in EditformSettings.I am trying to click the Add icon from the Grid to open a RadDataform to edit/insert.

 <telerik:RadGrid ID="RadGridUI" AllowFilteringByColumn="true" MasterTableView-EditMode="EditForms"
        FilterType="Classic"
        EnableHeaderContextMenu="true"
        EnableHeaderContextFilterMenu="true"
        AllowMultiRowEdit="false"
        AllowMultiRowSelection="false"
        AllowAutomaticUpdates="false"
        AllowAutomaticDeletes="false"
        AllowAutomaticInserts="false"
        OnNeedDataSource="RadGridUI_NeedDataSource"
        OnDeleteCommand="RadGridUI_DeleteCommand"
        OnFilterCheckListItemsRequested="RadGridUI_FilterCheckListItemsRequested"
        OnItemCreated="RadGridUI_ItemCreated"
        OnItemCommand="RadGridUI_ItemCommand" OnItemDataBound="RadGridUI_ItemDataBound"
        EnableLinqExpressions="false"
        ClientSettings-AllowColumnsReorder ="true" 
        AllowSorting="true" runat="server" Width="100%" CssClass="GenericGrid">

        <MasterTableView Width="100%" CommandItemDisplay="Top" ShowGroupFooter="true" AllowFilteringByColumn="true">
            <EditFormSettings EditFormType="Template">
                <EditColumn UniqueName="EditCommandColumn1" />
                <FormTemplate>
                    <uc1:PageUIControl IsBoundToGrid="true" runat="server" ID="EditFormControl"  />
                </FormTemplate>
                <PopUpSettings ScrollBars="None" />
            </EditFormSettings>

            <CommandItemTemplate>


                <div style="color:black!important;" >

                    <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGridUI.EditIndexes.Count == 0 %>'><i class="fa fa-pencil fa-lg"></i></asp:LinkButton>
                        <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGridUI.EditIndexes.Count > 0 %>'><i class="fa fa-pencil fa-lg"></i></asp:LinkButton>
                        <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGridUI.EditIndexes.Count > 0 || RadGridUI.MasterTableView.IsItemInserted %>'><i class="fa fa-ban fa-lg"></i></asp:LinkButton>&nbsp;&nbsp;
                       <asp:LinkButton ID="btnNew" runat="server" CommandName="InitInsert" Visible='<%# !RadGridUI.MasterTableView.IsItemInserted %>'><i class="fa fa-plus-square fa-lg"></i></asp:LinkButton>
                        <asp:LinkButton ID="btnInsert" runat="server" CommandName="PerformInsert" Visible='<%# RadGridUI.MasterTableView.IsItemInserted %>'><i class="fa fa-plus-square fa-lg"></i></asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="btnDelete" OnClientClick="javascript:return confirm('Delete all selected customers?')" runat="server" CommandName="DeleteSelected"><i class="fa fa-trash fa-lg"></i></asp:LinkButton>&nbsp;&nbsp;

                </div>

            </CommandItemTemplate>
        </MasterTableView>

        <ClientSettings>
            <Selecting AllowRowSelect="true"></Selecting>
            <ClientEvents OnGridCreated="GenericGridCreated"   />
            
        </ClientSettings>
    </telerik:RadGrid>

and the code where the raddataform is called in insert mode from grids itemcommand.:I tried all the ways in the below commented code:

 protected void RadGridUI_ItemCommand(object sender, GridCommandEventArgs e)
        {

            logHelper log = null;
            PageUIControl gridDataform;
            try
            {
                log = logHelper.getlogger(ref log, Logger: "RadGridUI_ItemCommand", userid: UserID, userContext: UserContext);
                UserContext = log.vUserObj;
                log.logDebug(logMessage: "RadGridUI_ItemCommand Start");
                log.TaskOrderID = TaskOrderID;


            if (e.CommandName == RadGrid.InitInsertCommandName)
            {
                e.Canceled = true;
                        log.logDebug(logMessage: "Setup Dataform for Insert");
                e.Item.OwnerTableView.InsertItem();
                    GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();

                    if (insertedItem == null)
                    { throw new Exception("No Inserted Item Found"); }

                    gridDataform = (PageUIControl)insertedItem.FindControl("EditFormControl");
                    gridDataform.UpdateMode = PageUIControl.Mode.Insert;
                    gridDataform.UserContext = this.UserContext;
                    gridDataform.UserID = this.UserID;
                    //String MyUserControlId = GridEditFormItem.EditFormUserControlID;
                    //    gridDataform = insertedItem.FindControl(MyUserControlId) as PageUIControl;

                    if (gridDataform == null)
                    { throw new Exception("No Grid Found"); }

                    log.logDebug(logMessage: "Fire Insert Mode for DataForm");

                  // gridDataform.DataForm.IsItemInserted = true;
                    //  gridDataform.DataForm.Rebind();
                     gridDataform.DataForm.Items[0].FireCommandEvent("InitInsert", "");
                  //  gridDataform.DataForm.ShowInsertItem();
                    //gridDataform.DataForm.DataSource=RadDataFormEmptyItem
                  //  gridDataform.DataForm.Items.FireCommandEvent("InitInsert", "");
                   // gridDataform.DataForm.Items[0].FireCommandEvent("InitInsert", "");
                   // gridDataform.DataForm.Items.Add();
                }
                else if (e.CommandName == "RowClick")
                    if (ItemCommand !=null)
                    { ItemCommand(sender, e); }
                    

            }
            catch (Exception ex)
            {
                log.logError(logMessage: "RadGridUI_ItemCommand Error: " + ex.Message );

                ((TextBox)TableUIErrorNotification.ContentContainer.FindControl("txtnot")).Text = log.logstr;
                TableUIErrorNotification.Show();
            }
            finally
            {
                log.logDebug(logMessage: "RadGridUI_ItemCommand Exit ");
                log.Flush(logger: "RadGridUI_ItemCommand");
            }

        }

I am also attaching the screen shot for better understanding of how the ui looks with the raddataform  which opens with the above working code if there is data in grid.

 

0
Vasil
Telerik team
answered on 30 Mar 2016, 08:00 AM
Hi Jyotsna,

The DataForm usage in your code is out of the designed usage of the control. DataForm itself is DataBound control and can be used stand-alone, or outside(but related) the grid

The EditForm of the grid does not need databound control inside. So your user control can just have the inputs, without wrapping them in DataForm. For reference see this demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/edit-form-types/defaultcs.aspx

Regards,
Vasil
Telerik
0
Chris
Top achievements
Rank 1
answered on 07 Jan 2017, 07:53 PM

So it was just too complicated to provide RadDataForm with a BeginEdit() method and a BeginInsert() method? Really Telerik, these objects have some very basic behaviors and we developers have some basic expectations that we can manipulate these behaviors without a bunch of code that looks like a workaround for a missing feature. Seriously, this is a data form. Data forms have three modes: View, Edit, and Insert. It should be intuitively obvious to an untrained monkey how to set a RadDataForm into any one of these three modes programmatically at any time. It should be obvious just by reading the intellisense prompts in Visual Studio.

0
Vasil
Telerik team
answered on 09 Jan 2017, 03:00 PM
Hi Chris,

I agree with you.

Lets relate this item here:
https://feedback.telerik.com/Project/108/Feedback/Details/210206-provide-methods-properties-for-easier-change-between-view-edit-insert-modes-of-ra

Regards,
Vasil
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Kiran
Top achievements
Rank 2
answered on 24 Jan 2019, 02:20 PM
Thank you. This did the trick for me.
0
Kiran
Top achievements
Rank 2
answered on 24 Jan 2019, 02:21 PM
Thank you Kevin. I was trying in Page Prerender until you made a mention of it.
Tags
DataForm
Asked by
Kevin
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Kevin
Top achievements
Rank 1
Bill Wolff
Top achievements
Rank 1
Viktor Tachev
Telerik team
Mike
Top achievements
Rank 1
Ole Oscar
Top achievements
Rank 1
jyotsna
Top achievements
Rank 1
Vasil
Telerik team
Chris
Top achievements
Rank 1
Kiran
Top achievements
Rank 2
Share this question
or