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>