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

EditFormType=template error when open edit form while insert form is open

2 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sf
Top achievements
Rank 1
sf asked on 11 Jan 2011, 10:19 AM
my edit form type uses Template.
when i click on Add New Item the template opens in insert mode,

in each item i have a linkbutton templatecolumn called "Edit" when click on it i run the code below to open the template in edit mode.
GridDataItem gdi = (GridDataItem)LinkButton1.Parent.Parent;
RadGrid1.Items[gdi.ItemIndex].Edit = true;
RadGrid1.Rebind();

If the Edit link is clicked while the template is opened in Insert Mode i get error.

Any idea how to avoid this problem?
thanks in advance

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Jan 2011, 11:54 AM
Hello,

If you wants to open edit form when clicking LinkButton, an easier way is setting CommandName for LinkButton as 'Edit' and that's will avoid the code written manually for putting in editmode.
What type of error you are getting and could you please elaborate your scenario/ give code for the scenario if it doesn't help?

-Shinu.
0
sf
Top achievements
Rank 1
answered on 12 Jan 2011, 02:01 AM
thanks Shinu
I decided to use RadMenu items for any actions to be taken for each item in the grid. I call the RadMenu "Action". It looks like:
<telerik:GridTemplateColumn HeaderText="Actions" DataField="QId" UniqueName="Actions">
    <ItemTemplate>
        <telerik:RadMenu ID="ActionMenu" onItemClick="ActionMenu_Click">
            <Items>
                <telerik:RadMenuItem Text="Action">
                    <Items>
                        <telerik:RadMenuItem Text="Edit"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Delete"></telerik:RadMenuItem>
                    </Items>
                </telerik:RadMenuItem>
            </Items>
        </telerik:RadMenu>
    </ItemTemplate>
</telerik:GridTemplateColumn>


If the Edit menu item is selected, in ActionMenu_Click event I do:

GridDataItem gdi = (GridDataItem)LinkButton1.Parent.Parent;
RadGrid1.Items[gdi.ItemIndex].Edit = true;
RadGrid1.Rebind();

I use the default commanditem for Insert.

When I click on the Edit menu item without the insert form opened it works fine. If I click on the Edit menu item with the insert form opened error happens:
Error: Sys.WebForms.PageRequestManagerServerErrorException: Specified cast is not valid.

Then If I start debugging the error seems to be related to a <asp:CheckBox> item in the edit template form. Which caused the ActionMenu_Click method the line: "RadGrid1.Rebind()" to malfunction.

I think I need to somehow close the Insert form while its open when the "Edit" menu item in the RadMenu is clicked. However I couldn't figure out how to do this..
Tags
Grid
Asked by
sf
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
sf
Top achievements
Rank 1
Share this question
or