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

how can i find RadGrid EditFormTemplete fields on EntityDataSource Insert and Update Events before

5 Answers 115 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kd
Top achievements
Rank 1
kd asked on 30 Jan 2012, 02:02 PM
Hi all,
I am new one for telerik controlls, my scenario is following
i have one mater grid and its detail grid and both gird have EditFormTemplete it means i want to add, update both master and details tablse through editform templete fields, and i have bound master and details gird with entityDataSource object control so i want to insert through EntityDataSource Object onInsert Event . i wrote insert event of entity data source like this and it works fine

protected void OnAllMembersInserting(object sender, EntityDataSourceChangingEventArgs e)
        {
            try
            {
                GridEditFormItem editedItem = (GridEditFormItem)(rg_AllMembers.MasterTableView.GetItems(GridItemType.EditFormItem)[0]);
                if (editedItem != null)
                {
                    DAL.UserProfile uP = (DAL.UserProfile)e.Entity;
                    uP.RoleName = (editedItem.FindControl("rdbtnRegisterAs") as RadioButtonList).SelectedIndex.Equals(0) ? HunchClub.Common.Constants.RoleNames.Bidders : HunchClub.Common.Constants.RoleNames.Sellers;
                    uP.RegisteredDate = DateTime.UtcNow;
                    uP.RegisteredIPAddress = Common.Utility.Operations.GetUserIPAddress();
                    uP.islock = (editedItem.FindControl("chkIsLock") as CheckBox).Checked;

                    BLL.BO.Profile.Members m = new BLL.BO.Profile.Members();
                    string[] outMessage = new string[] { };
                    string UserID = HunchClub.BLL.BO.Profile.aspMembership.CreateNewUser(uP.PrimaryEmailAddress, (editedItem.FindControl("txtPassword") as RadTextBox).Text, uP.PrimaryEmailAddress, true, out outMessage);//isApprove is false until user verify email address
                    if (!string.IsNullOrEmpty(UserID))
                    {
                        HunchClub.BLL.BO.Profile.aspMembership.AddUserToRole(uP.PrimaryEmailAddress, uP.RoleName);
                        uP.ID = Guid.Parse(UserID);
                    }
                }
            }

so how can i find such fields on update when i write this line for finding controls
GridEditFormItem editedItem = (GridEditFormItem)(rg_AllMembers.MasterTableView.GetItems(GridItemType.EditFormItem)[0]);
it gives all null controls

is there any one can help me how can i find master and details editforms fiedls with sample code

5 Answers, 1 is accepted

Sort by
0
RvdGrint
Top achievements
Rank 1
answered on 31 Jan 2012, 10:12 PM
kd,

try this

GridEditFormItem _item = ((GridDataItem)rg_AllMembers.EditItems[0]).EditFormItem;


Regards, 
  Jos.
0
kd
Top achievements
Rank 1
answered on 01 Feb 2012, 06:30 AM
Thanks for reply
i am using EditForm templete
so this  is working fine

GridEditFormItem editedItem = (GridEditFormItem)(rg_AllMembers.MasterTableView.GetItems(GridItemType.EditFormItem)[0]);

but i want to get it through row index because in the above code i have fixed it with Zero index and i want to get it through Current edit index of RadGrid
i did this through this logic but its not better for performance if gird have more than thousand rows

CheckBox chkIsLock = null;
RadTextBox username=null;
                foreach (GridDataItem masterItem in rg_AllMembers.MasterTableView.Items)
                {
                    GridEditFormItem item = masterItem.EditFormItem;
                    if (item.IsInEditMode)
                    {
                        chkIsLock = item.FindControl("chkIsLock") as CheckBox;
                        username = item.FindControl("txtUserName") as RadTextBox;
                        break;
                    }
                }
finally i initialize objects through found controls value like this
DAL.UserProfile uP = (DAL.UserProfile)e.Entity;
                uP.lastupdate = DateTime.UtcNow;
                uP.islock = chkIsLock.Checked;
                uP.UserName = username.Text;

My Questions is follows
1)how can i get it directly through row index not through itration of each row?
2)how can i find EditForm templete fields which inside the master table ?
         
0
Accepted
RvdGrint
Top achievements
Rank 1
answered on 01 Feb 2012, 08:04 AM
kd,

I'm also using EditForm templates in my solution.
If you use my approach:
GridEditFormItem _item = ((GridDataItem)rg_AllMembers.EditItems[0]).EditFormItem;

Then _item is the first EditForm item. If you allow multiple edit items than you should loop over the EditItems collection like:
for (int iItem = 0; iItem < rg_AllMembers.EditItems.Count; iItem++)
{
  GridEditFormItem _item = ((GridDataItem)rg_AllMembers.EditItems[iItem]).EditFormItem;
}

Regards,
  Jos


0
kd
Top achievements
Rank 1
answered on 01 Feb 2012, 10:28 AM
thanks for rpl
it works in master table editform templete but how can i find detailtable edit form templete fields? because i am using master and detail edit form templets so how can i find detail table edit form templete
0
Tsvetina
Telerik team
answered on 06 Feb 2012, 08:02 AM
Hi,

You could set the Name property of each GridTableView and then loop through the edit items and check (rg_AllMembers.EditItems[iItem]).OwnerTableView.Name (the collection includes all edit items in the grid). This way you could recognize when an edit form belongs to the detail table of interest.

Greetings,
Tsvetina
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
General Discussions
Asked by
kd
Top achievements
Rank 1
Answers by
RvdGrint
Top achievements
Rank 1
kd
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or