I want to use two different WebUserControl forms , one for insert and one for edit.
I have tried the following logic to implement this. But it is not working.
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
e.Canceled = true;
RadGrid1.EditIndexes.Clear();
e.Item.OwnerTableView.EditFormSettings.UserControlName = "MyInsertFormUserControl.ascx";
e.Item.OwnerTableView.InsertItem();
}
else if (e.CommandName == RadGrid.EditCommandName)
{
e.Item.OwnerTableView.IsItemInserted = false;
e.Item.OwnerTableView.EditFormSettings.UserControlName = "EmployeeDetailsVB.ascx";
}
}
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
e.Canceled = true;
RadGrid1.EditIndexes.Clear();
e.Item.OwnerTableView.EditFormSettings.UserControlName = "MyInsertFormUserControl.ascx";
e.Item.OwnerTableView.InsertItem();
}
else if (e.CommandName == RadGrid.EditCommandName)
{
e.Item.OwnerTableView.IsItemInserted = false;
e.Item.OwnerTableView.EditFormSettings.UserControlName = "EmployeeDetailsVB.ascx";
}
}
7 Answers, 1 is accepted
0
Hi Rita,
Kind regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Can you specify what exactly is not working? Have you set EditFormType="WebUserControl" in the EditFormSettings properties of the respective GridTableView?
Any detailed sample code or description of your scenario would be helpful in identifying the source for this issue.
Kind regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mike
Top achievements
Rank 2
answered on 18 Feb 2010, 04:00 AM
I would be very interested in the answer to this scenario as well. I have the same situation where I need to use 2 different usercontrols, one for insert and one for update. I have used the same coding as Rita has shown above.
When I have all the edit items inside the following all updates work nicely:
<EditFormSettings EditFormType="Template">
<FormTemplate>
...
</FormTemplate>
</EditFormSettings>
but as soon as I change this to the following:
<EditFormSettings EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
updating does not work anymore and yet the usercontrol has exactly the same content as the <FormTemplate> above, it says it can't insert NULL values etc into the fields that require values.
The DB has default values etc. and this does not happen inside the:
<EditFormSettings EditFormType="Template">
<FormTemplate>
only when I remove it and place it into a usercontrol.
Any idea why this is the case?
Thanks in advance
Grant
0
Hi Grant,
Let me try to explain this in detail. RadGrid supports 3 modes of editing (specified by RadGrid.MasterTableView.EditMode):
1. InPlace (the edit controls are loaded in the same edited row)
2. EditForms(the edit controls are loaded below the edited row)
3. Popup(the edit controls are loaded in a popup window).
Choosing EditForms or PopUp, you further have 3 options for the edit form controls inside (specififed by the GridTableView.EditFormSettings.EditFormType property):
1. AutoGenerated
2. Template
3. WebUserControl
If you choose to have Template edit form, you define your edit controls in the FormTemplate of the EditFormSettings. If you choose to go with WebUserControl, you need to specify EditFormSettings.USerControlName to the name of the user control you will beloading.
You cannot mix these types of edit forms. You can either have Template or WebUserControl.
Kind regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Let me try to explain this in detail. RadGrid supports 3 modes of editing (specified by RadGrid.MasterTableView.EditMode):
1. InPlace (the edit controls are loaded in the same edited row)
2. EditForms(the edit controls are loaded below the edited row)
3. Popup(the edit controls are loaded in a popup window).
Choosing EditForms or PopUp, you further have 3 options for the edit form controls inside (specififed by the GridTableView.EditFormSettings.EditFormType property):
1. AutoGenerated
2. Template
3. WebUserControl
If you choose to have Template edit form, you define your edit controls in the FormTemplate of the EditFormSettings. If you choose to go with WebUserControl, you need to specify EditFormSettings.USerControlName to the name of the user control you will beloading.
You cannot mix these types of edit forms. You can either have Template or WebUserControl.
Having said that, the example for using different edit forms for insert and edit referred to the WebUserControl option only. In this case, specifying FormTemplate is superfluous. You need to specify UserControlName instead.
For more information you can refer to the following RadGrid help articles:
Custom edit forms
Different edit forms on edit and insert
Kind regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rita15
Top achievements
Rank 1
answered on 19 Feb 2010, 11:00 PM
Hi Veli,
Thanks for the response.
If i use the same form for edit and insert then everything works fine.
As per my project requirement, in inserting mode, few fields need to be populated, but in updating mode, all the fields which are populated during insert mode need to be read only and there are other fields which are also populated during updating mode.So I was thinking, may be I will use 2 different webuser controls, one for insert and one for update.
Unless there are other ways to achieve the same goal. I tried to use Enabled='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? true : false %>' for all the controls I need to be read only in updating mode.
Is there a way to distinguish between insert and update mode inside the webusercontrol or grid? I tried to use RadGrid1_ItemCreated(), but it is not working.
Thanks,
Rita
Thanks for the response.
If i use the same form for edit and insert then everything works fine.
As per my project requirement, in inserting mode, few fields need to be populated, but in updating mode, all the fields which are populated during insert mode need to be read only and there are other fields which are also populated during updating mode.So I was thinking, may be I will use 2 different webuser controls, one for insert and one for update.
Unless there are other ways to achieve the same goal. I tried to use Enabled='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? true : false %>' for all the controls I need to be read only in updating mode.
Is there a way to distinguish between insert and update mode inside the webusercontrol or grid? I tried to use RadGrid1_ItemCreated(), but it is not working.
Thanks,
Rita
| <asp:button ID="Button1" Text='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? "Insert" : "Update" %>' |
| runat="server" CommandName='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? "PerformInsert" : "Update" %>'></asp:button> |
| <asp:button id="btnCancel" text="Cancel" runat="server" causesvalidation="False" commandname="Cancel"></asp:button></td> |
| protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridEditFormItem && e.Item.IsInEditMode) |
| { |
| Telerik.Web.UI.RadTextBox test = (Telerik.Web.UI.RadTextBox)e.Item.FindControl("Comment"); |
| test.Visible = false; |
| } |
| } |
0
Princy
Top achievements
Rank 2
answered on 20 Feb 2010, 05:53 AM
Hi,
Here is a link on Distinguish edit/insert mode on ItemCreated/ItemDataBound that you might find helpful.
Thanks,
Princy
0
Rita15
Top achievements
Rank 1
answered on 20 Feb 2010, 08:33 AM
Hi Princy,
I have looked at the article, still I am trying to figure out how "RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)" will get called from the button specified in the web user control.
I have looked at the article, still I am trying to figure out how "RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)" will get called from the button specified in the web user control.
<asp:Button ID="btnUpdate" Text='<%#
IIf( DataBinder.Eval(Container,
"OwnerTableView.IsItemInserted"), "Insert",
"Update") %>'
runat="server" CommandName='<%# IIf( DataBinder.Eval(Container, "OwnerTableView.IsItemInserted"), "PerformInsert", "Update") %>'>
sample code might help to understand it better.
Thanks,
Rita
runat="server" CommandName='<%# IIf( DataBinder.Eval(Container, "OwnerTableView.IsItemInserted"), "PerformInsert", "Update") %>'>
sample code might help to understand it better.
Thanks,
Rita
0
Accepted
Hi Rita,
ItemCreated is an automatic event that is fired for every RadGrid item when the latter is created. The event is fired on every postback. You cannot explicitly fire this event.
Sincerely yours,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
ItemCreated is an automatic event that is fired for every RadGrid item when the latter is created. The event is fired on every postback. You cannot explicitly fire this event.
As Princiy pointed, you can distinguish between the edit and insert modes with the demonstrated expression in the markup. And on the server, again in ItemCreated, you can have:
protectedvoidRadGrid1_ItemCreated(objectsender, GridItemEventArgs e){if(e.ItemisGridEditableItem && e.Item.IsInEditMode){if(e.Item.OwnerTableView.IsItemInserted){//use e.Item.FindControl() to find controls to disable on insert}else{//use e.Item.FindControl() to find controls to disable on update}}}
So, that's the case when you are using one and the same edit form for update and insert. Only, you are disabling some controls and leaving others.
On the other hand, if you want to use web user control edit forms, and have 2 different ones for edit and insert, you can use the ItemCommand event in the grid to toggle between the two:
protectedvoidRadGrid1_ItemCommand(objectsource, Telerik.Web.UI.GridCommandEventArgs e){if(e.CommandName == RadGrid.InitInsertCommandName){e.Canceled =true;RadGrid1.EditIndexes.Clear();e.Item.OwnerTableView.EditFormSettings.UserControlName ="MyInsertFormUserControl.ascx";//load the insert forme.Item.OwnerTableView.InsertItem();}elseif(e.CommandName == RadGrid.EditCommandName){e.Item.OwnerTableView.IsItemInserted =false;e.Item.OwnerTableView.EditFormSettings.UserControlName ="EmployeeDetailsVB.ascx";//load the update form}}
This second approach is demonstrated in the previously referred help article.
Sincerely yours,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.