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

Double entry on insert

5 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 26 Feb 2009, 11:04 PM
Hi All

Why does my gridview insert 2 records on insert. Its not just the insert, I was testing the control values by writing to a literalControl, and this showed twice.

I'm using a data class to fill and form template editing.

Any Ideas. here is my grid code: (I actually have a nested grid but I've taken that portion out to save space - could that be the problem?

Andy

<telerik:RadGrid

             ID="rgRisk"

             runat="server"

             GridLines="None"

             AutoGenerateColumns="False"

             ShowStatusBar="True"

             Skin="Expert"

             EnableEmbeddedSkins="False" 

             OnDetailTableDataBind="rgRisk_DetailTableDataBind"

             OnNeedDataSource="rgRisk_NeedDataSource"

             OnUpdateCommand="rgRisk_UpdateCommand"

             OnInsertCommand="rgRisk_InsertCommand"

             OnDeleteCommand="rgRisk_DeleteCommand" >

              

               <MasterTableView GridLines="Horizontal" CommandItemDisplay="Top" DataKeyNames="Risk_Area_ID" Width="100%" NoMasterRecordsText="No Risk Areas" NoDetailRecordsText="No Risks Identified" >

              

              

                   <Columns>

                      

                       <telerik:GridEditCommandColumn CancelImageUrl="../App_Themes/Expert/Grid/Cancel.gif" EditImageUrl="../App_Themes/Expert/Grid/Edit.gif" InsertImageUrl="../App_Themes/Expert/Grid/Update.gif" UpdateImageUrl="../App_Themes/Expert/Grid/Update.gif" ButtonType="ImageButton"><HeaderStyle Width="15px" /><ItemStyle Width="15px" /></telerik:GridEditCommandColumn>

                      

                       <telerik:GridBoundColumn DataField="Risk_Area" EmptyDataText="&amp;nbsp;" HeaderText="Risk Area" ></telerik:GridBoundColumn>

                         

                       <telerik:GridExpandColumn><HeaderStyle Width="10px" /><ItemStyle Width="10px" /></telerik:GridExpandColumn>

                      

                       <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete" ImageUrl="../App_Themes/Expert/Grid/delete.gif" UniqueName="column"><HeaderStyle Width="10px" /><ItemStyle Width="10px" /></telerik:GridButtonColumn>

                              

                   </Columns>

                  

                    <EditFormSettings EditFormType="Template">

                   

                        <EditColumn UniqueName="EditCommandColumn1"> </EditColumn>

 

                        <EditColumn CancelImageUrl="../App_Themes/Expert/Grid/Cancel.gif" EditImageUrl="../App_Themes/Expert/Grid/Edit.gif" InsertImageUrl="../App_Themes/Expert/Grid/Update.gif" UpdateImageUrl="../App_Themes/Expert/Grid/Update.gif" ButtonType="ImageButton" ></EditColumn>

                            <FormTemplate>

                                <div>

                                    <label class="gridlabel">Risk Area / Room:</label><telerik:RadTextBox ID="txtRiskArea" runat="server" Width="300px" Text='<%# Eval( "Risk_Area" ) %>' CssClass="gridtext"></telerik:RadTextBox>

                                </div>

                                <div>

                                    <asp:Button ID="btnUpdate" cssclass="gridbtn" Text='<%#iif(TryCast(Container, GridItem).OwnerTableView.IsItemInserted, "Insert","Update")  %>' runat="server" CommandName='<%# iif(TryCast(Container, GridItem).OwnerTableView.IsItemInserted, "PerformInsert", "Update" )%>'></asp:Button> 

                                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="False" cssclass="gridbtn" CommandName="Cancel"/>  

                                </div>

                            </FormTemplate> 

                    </EditFormSettings>

                          

                   <CommandItemSettings AddNewRecordText="Add new area" /><RowIndicatorColumn><HeaderStyle Width="20px" /></RowIndicatorColumn>

                                     

               </MasterTableView>

              

               <FilterMenu EnableEmbeddedSkins="False" EnableTheming="True" Skin="Expert"><CollapseAnimation Duration="200" Type="OutQuint" /></FilterMenu>

              

           </telerik:RadGrid>

5 Answers, 1 is accepted

Sort by
0
Andy Green
Top achievements
Rank 2
answered on 27 Feb 2009, 08:40 AM
A Thought

I have 2 nested grids - but in my insert code I'm not differentiating between which one is doing the update (I've not looked at the second one yet), so could it be that the insert in running once for each grid?

Andy
0
Andy Green
Top achievements
Rank 2
answered on 01 Mar 2009, 10:19 PM
Its not a 2 nested grid issue, I've checked the grid I want to update ad only run code for that grid, and I have 2 updates, in desperation I deleted the nested grid, and it sill does it.

Msut be a on postack / page load problem I think.

Does anyone have any ideas.

Andy
0
Accepted
Sebastian
Telerik team
answered on 02 Mar 2009, 03:29 PM
Hello Andy,

Is it possible that you are writing in VB.NET language and attached the event handlers for the grid twice (once declarative in the markup and once with Handles clause in the code-behind)? This can result in duplicate event firing in your case.

Regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andy Green
Top achievements
Rank 2
answered on 04 Mar 2009, 03:29 PM
Spot on thank you.

I had the following in my radgrid

OnUpdateCommand="rgRisk_UpdateCommand"

OnInsertCommand="rgRisk_InsertCommand"

OnDeleteCommand="rgRisk_DeleteCommand"


Andy
0
Pam
Top achievements
Rank 2
answered on 24 Jan 2013, 07:32 PM
This thread was very helpful and very simple to understand. I encountered the same situation and it was a good lesson for me not to put both a handler on code behind and on markup.
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Andy Green
Top achievements
Rank 2
Sebastian
Telerik team
Pam
Top achievements
Rank 2
Share this question
or