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

RadGrid InsertCommand Fires after page refreshing

2 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bahram
Top achievements
Rank 2
Bahram asked on 24 Jul 2011, 05:02 PM

Hello everybody,
I have encountered a problem in dealing with Radgrid,I have a aspx page with 3 UserControl inside of the page.This UserControls will be added at runtime(each in a tabstrip) and within the controls I have a Radgrid which have my ownn Custom logic and Insert,update and delete have been done in code-behind.
when I do Insert, it is perfect but when i refresh the page after doing insert,the InsertCommand of my RadGrid will be Fired again and insert the same record again.
Here is my Source Code


 

 

 

 

 

protected

 

 

void RadGridPanel_InsertCommand(object sender, GridCommandEventArgs e) 
  
   
  
{
  
   
  
   
  
GridEditFormInsertItem insertItem = e.Item as GridEditFormInsertItem; 
  
   
  
   
  
   
  
GridEditableItem item = e.Item as GridEditableItem; 
  
   
  
   
  
   
  
tbl_Panel _tbl_Panel = new tbl_Panel(); 
  
   
  
item.UpdateValues(_tbl_Panel);
  
DbContext_Panel.AddTotbl_Panel(_tbl_Panel);
  
DbContext_Panel.SaveChanges();
  
}

 

<telerik:RadGrid  ID="RadGridPanel" CssClass="myRadGrid" GridLines="None" runat="server"  AllowAutomaticDeletes="True"
             PageSize="4"  AllowPaging="True" 
            AutoGenerateColumns="False"  OnItemUpdated="RadGridPanel_ItemUpdated"
            OnItemDeleted="RadGridPanel_ItemDeleted" OnItemInserted="RadGridPanel_ItemInserted" 
                OnDataBound="RadGridPanel_DataBound" AllowFilteringByColumn="True" 
                OnItemCreated="RadGridPanel_ItemCreated"
                oninsertcommand="RadGridPanel_InsertCommand" 
                OnUpdateCommand="RadGridPanel_UpdateCommand" 
                OnNeedDataSource="RadGridPanel_NeedDataSource" 
                oneditcommand="RadGridPanel_EditCommand" onitemdatabound="RadGridPanel_ItemDataBound" ondeletecommand="RadGridPanel_DeleteCommand"
                >
            <%--<PagerStyle Mode="NextPrevAndNumeric" />--%>
             <SelectedItemStyle Font-Names="Tahoma"  Font-Size="11px"   ForeColor="#8abe23"  /> 
            <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="PanelId"
                 HorizontalAlign="NotSet" AutoGenerateColumns="False"  Font-Names="Tahoma" EditMode="InPlace"  EditFormSettings-FormStyle-ForeColor="Black" Font-Size="11px">
                 <CommandItemTemplate>
                    <div style="padding: 5px 5px;" dir="rtl">
                   <asp:LinkButton ID="LinkButton2" runat="server" Font-Names="Tahoma" CommandName="InitInsert" Visible='<%# !RadGridPanel.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" src="../Images/Icons/AddRecord.gif" />اضافه كردن ركورد جديد</asp:LinkButton>  
                        <asp:LinkButton ID="LinkButton4" runat="server"  Font-Names="Tahoma" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Icons/Refresh.gif" />به روزآوري اطلاعات</asp:LinkButton>
                    </div>
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                        <ItemStyle CssClass="MyImageButton" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridButtonColumn ConfirmText="آيا از حذف ركورد جاري مطمئنيد؟" ConfirmDialogType="RadWindow"
                        ConfirmTitle="حذف ركورد جاري" ButtonType="ImageButton" CommandName="Delete" Text="حذف"
                        UniqueName="DeleteColumn">
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                    </telerik:GridButtonColumn>
                    <telerik:GridBoundColumn DataField="PanelName" HeaderText="پنل " SortExpression="PanelName"
                        UniqueName="PanelName" ColumnEditorID="GridTextBoxColumnPanelName">
                    </telerik:GridBoundColumn>
  
                    <telerik:GridBoundColumn DataField="Address" Display="False" EditFormColumnIndex="2" HeaderText=" آدرس "  SortExpression="Address"
                        UniqueName="Address" ColumnEditorID="GridTextBoxColumnAddress">
                    </telerik:GridBoundColumn>
  
                     <telerik:GridBoundColumn DataField="Tellphone" HeaderText="تلفن " SortExpression="Tellphone"
                        UniqueName="Tellphone" ColumnEditorID="GridTextBoxColumnTellphone">
                    </telerik:GridBoundColumn>
                    <telerik:GridDropDownColumn DataField="SiteOwnerId" EditFormColumnIndex="0" HeaderText="شركت" UniqueName="SiteOwnerId" ListTextField="SiteOwnerName"
                     ListValueField="SiteOwnerId" ColumnEditorID="GridDropDownColumnSiteOwnerId">
                    </telerik:GridDropDownColumn>
                                        
                </Columns>
                <EditFormSettings ColumnNumber="3" CaptionDataField="PanelName"  CaptionFormatString="ويرايش اطلاعات" InsertCaption="" >
                   <FormTableItemStyle Wrap="True" ></FormTableItemStyle>
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" 
                        Width="100%" />
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" Font-Names="Tahoma" />
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn ButtonType="ImageButton" InsertText="ثبت پنل" UpdateText="ويرايش پنل"
                        UniqueName="EditCommandColumn1" CancelText="لغو ويرايش">
                    </EditColumn>
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                </EditFormSettings>
            </MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
            </ClientSettings>
        </telerik:RadGrid>

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Jul 2011, 06:57 AM
Hello Bahram,

Check the following forum thread which discussed similar scenario.
refresh fires insertcommand .

Thanks,
Princy.
0
Nizar
Top achievements
Rank 1
answered on 03 Aug 2011, 07:13 PM
Hi Princy,

I have the same issue where I'm following your "Peform Batch Updates" scenario, with an added option to insert a new record as well. If I add a new record, and hit the update all command button, all goes well, but then I get a new insert row in the grid. How can I stop this?
Tags
Grid
Asked by
Bahram
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Nizar
Top achievements
Rank 1
Share this question
or