Hi there,
From what i understand, the EditFormType property affects inserts AND updates. Is it possible to use different methods for each approach?
For example...
I have a grid that displays a list of products. I want to use a custom usercontrol for the insert so that users may "search" for a product before inserting a new one. For updates however, i just want to use the auto-generated "update" row.
Is this possible?
From what i understand, the EditFormType property affects inserts AND updates. Is it possible to use different methods for each approach?
For example...
I have a grid that displays a list of products. I want to use a custom usercontrol for the insert so that users may "search" for a product before inserting a new one. For updates however, i just want to use the auto-generated "update" row.
Is this possible?
3 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 27 Oct 2008, 10:28 AM
Hello Nick,
You can try out the following code to display a UserControlForm for InsertMode of the grid and the auto-generated form for EditMode.
cs:
Thanks
Princy.
You can try out the following code to display a UserControlForm for InsertMode of the grid and the auto-generated form for EditMode.
cs:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
{ |
if (e.CommandName == RadGrid.InitInsertCommandName) |
{ |
e.Canceled = true; |
RadGrid1.EditIndexes.Clear(); |
e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl; |
e.Item.OwnerTableView.EditFormSettings.UserControlName = "WebUserControl.ascx"; |
e.Item.OwnerTableView.InsertItem(); |
} |
else if (e.CommandName == RadGrid.EditCommandName) |
{ |
e.Item.OwnerTableView.IsItemInserted = false; |
e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.AutoGenerated; |
} |
} |
Thanks
Princy.
0

Nick
Top achievements
Rank 1
answered on 27 Oct 2008, 11:33 AM
Thanks Princy, this achieves the desired behaviour, however i can now no longer add and edit at the same time. As soon as i click "Edit", the add usercontrol disappears and vice versa.
I figured as an alternative, that i might instead be able to set the EditFormType to WebUserControl and just pass a value of "Edit" or "Add" to the usercontrol to get it to display in two seperate modes.
I tried this with the following code, however the first line (where i attempt to retrieve the usercontrol) always returns null. Any ideas?
I figured as an alternative, that i might instead be able to set the EditFormType to WebUserControl and just pass a value of "Edit" or "Add" to the usercontrol to get it to display in two seperate modes.
I tried this with the following code, however the first line (where i attempt to retrieve the usercontrol) always returns null. Any ideas?
protected void RadGrid_ItemCommand(object source, GridCommandEventArgs e) |
{ |
MyUserControl userControl = (MyUserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
switch (e.CommandName) |
{ |
case RadGrid.InitInsertCommandName: |
myUserControl.Mode = ModeEnum.Add; |
break; |
case RadGrid.EditCommandName: |
myUserControl.Mode = ModeEnum.Edit; |
break; |
} |
} |
0

Princy
Top achievements
Rank 2
answered on 27 Oct 2008, 01:02 PM
Hi,
Try accessing the UserControl in the ItemDataBound event and set the mode to add or edit .Try altering the code below:
CS:
Thanks,
Princy
Try accessing the UserControl in the ItemDataBound event and set the mode to add or edit .Try altering the code below:
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item.ItemType == Telerik.WebControls.GridItemType.EditFormItem) && (e.Item.IsInEditMode)) |
{ |
MyUserControl userControl = (MyUserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
myUserControl.Mode = ModeEnum.Edit; |
} |
if (e.Item is GridEditFormInsertItem) |
{ |
MyUserControl userControl = (MyUserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
myUserControl.Mode = ModeEnum.Add; |
} |
} |
Thanks,
Princy