Hi,
I am using telerik grid and editfromtemplate, and what happen is that whenever I refresh the page after inserting a record in telerik grid. It makes one more entry in the grid and in the database. I want to prevent this behaviour of grid because it's causing duplicate number of records in my grid.
I am using telerik grid and editfromtemplate, and what happen is that whenever I refresh the page after inserting a record in telerik grid. It makes one more entry in the grid and in the database. I want to prevent this behaviour of grid because it's causing duplicate number of records in my grid.
Imports Telerik.Web.UIPartial Class SNR_Config Inherits System.Web.UI.UserControl Private dbContext As New SNRDentonDBLayerDataContext Protected Sub rgConfiguration_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgConfiguration.NeedDataSource BindGrid() End Sub Protected Sub BindGrid() Dim IConfig = From Config In dbContext.SNR_Configurations Order By Config.ID Descending Select Config rgConfiguration.DataSource = IConfig.ToList End Sub Protected Sub rgConfiguration_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgConfiguration.ItemCommand If e.CommandName = RadGrid.PerformInsertCommandName Then Insert(e) ElseIf e.CommandName = RadGrid.UpdateCommandName Then Update(e) ElseIf e.CommandName = "Delete" Then Delete(e) End If End Sub Protected Sub Insert(ByVal e As Telerik.Web.UI.GridCommandEventArgs) If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.IsInEditMode Then If e.Item.OwnerTableView.IsItemInserted Then Dim txtKey As TextBox = e.Item.FindControl("txtKey") Dim txtValue As TextBox = e.Item.FindControl("txtValue") Dim chkIsAdmin As CheckBox = e.Item.FindControl("chkIsAdmin") Dim con As New SNR_Configuration con.ConfigKey = txtKey.Text.Trim con.ConfigValue = txtValue.Text.Trim con.CreatedOn = DateTime.Now con.CreatedBY = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo.UserID con.IsDeleted = False con.IsAdmin = IIf(chkIsAdmin.Checked, True, False) dbContext.SNR_Configurations.InsertOnSubmit(con) dbContext.SubmitChanges() End If End If End Sub Protected Sub rgConfiguration_ItemDataBound(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgConfiguration.ItemDataBound If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then If TypeOf e.Item Is GridEditableItem And TypeOf e.Item Is GridEditFormInsertItem Then Dim btnInsert As Button = e.Item.FindControl("btnInsert") btnInsert.Visible = True Else Dim btnUpdate As Button = e.Item.FindControl("btnUpdate") btnUpdate.Visible = True End If End If End Sub End Class