I am trying to accomplish using a single Radgrid for 7 different tables. (one aspx page) I am also wrapping my datasource updates (CRUD) in a Property procedure. It is working pretty well except for inserting a new row in a table. My problem is that it is posting the update to the radgrid control and the database twice, I have spent many hours trying to debug my problem using the call stack and various other methods and what I have determined is that when I press the Insert link button (in-place editing), it is running the Radgrid_InsertCommand procedure twice and I am going slowly mad trying to figure out why. My code is attached, This could be a real challenge for the telerik MVPs. (or not!) Thanks in advance. (if I could, I would award 1000 points - but that's another site ;->)
P.S. The Delete and Update commands work just fine using this code. The difference is the insert process is activated from a RadButton outside the grid. My aspx file has only the OnInsert, OnDelete, OnUpdate Commands.and the various SQLDataSources The grid columns are built dynamically in code behind depending on the table the user chooses.
P.S. The Delete and Update commands work just fine using this code. The difference is the insert process is activated from a RadButton outside the grid. My aspx file has only the OnInsert, OnDelete, OnUpdate Commands.and the various SQLDataSources The grid columns are built dynamically in code behind depending on the table the user chooses.
Protected Sub rgDisplay_InsertCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles rgDisplay.InsertCommand Dim editeditem As GridEditableItem = CType(e.Item, GridEditableItem) Dim dataTbl As DataTable = Me.GridSource Dim newRow As DataRow = dataTbl.NewRow Try 'calculate the next record key cmd.CommandText = "SELECT MAX(CMT_REC_ID) FROM tblTSComments" cmd.Connection = conn conn.Open() intLastKey = Convert.ToInt16(cmd.ExecuteScalar().ToString) intLastKey += 1 Finally conn.Close() End Try Dim newValues As Hashtable = New Hashtable e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editeditem) Try For Each entry As DictionaryEntry In newValues If entry.Key = "CMT_REC_ID" Then newRow("CMT_REC_ID") = intLastKey Else newRow(entry.Key) = entry.Value End If Next dataTbl.Rows.Add(newRow) Me.GridSource = dataTbl Catch ex As Exception ' Error message goes here e.Canceled = True End Try End SubPrivate Property GridSource As DataTable Get Dim obj As Object = Me.ViewState("_gvs") If (Not obj Is Nothing) Then Return CType(obj, DataTable) Else Dim intRpt As Integer = Request("Report") Select Case intRpt Case 0 'Comments adp.SelectCommand = New OleDbCommand("SELECT CMT_REC_ID, CMT_DESCRIPTION FROM tblTSComments", conn) Dim cmtstbl As New DataTable conn.Open() Try adp.Fill(cmtstbl) Finally conn.Close() End Try Me.ViewState("_gvs") = cmtstbl Return cmtstbl Case 1 'Teams adp.SelectCommand = New OleDbCommand("SELECT CT_TEAM_REC_ID, CT_TEAM_NAME, CT_REPORTS_TO FROM tblControllerTeam", conn) Dim teamTbl As New DataTable conn.Open() Try adp.Fill(teamTbl) Finally conn.Close() End Try Me.ViewState("_gvs") = teamTbl Return teamTbl Case 2 'Status adp.SelectCommand = New OleDbCommand("SELECT TCS_STATUS_CODE, TCS_DESCRIPTION FROM tblEmplStatus", conn) Dim statusTbl As New DataTable conn.Open() Try adp.Fill(statusTbl) Finally conn.Close() End Try Me.ViewState("_gvs") = statusTbl Return statusTbl Case 3 'PayPeriod adp.SelectCommand = New OleDbCommand("SELECT PAYPERIOD, PAYPERIODNBR, PAYPERIODLOCKED, PAYPERIODLOCKEDDATE, PAYPERIODLOCKID FROM PayPeriods ORDER BY PAYPERIOD", conn) Dim ppTbl As New DataTable conn.Open() Try adp.Fill(ppTbl) Finally conn.Close() End Try Me.ViewState("_gvs") = ppTbl Return ppTbl Case 4 'Team Leader adp.SelectCommand = New OleDbCommand("SELECT OPF_NTUSER_ID, OPF_FNAME, OPF_MINIT, OPF_LNAME, OPF_REGION FROM tblOpsFacilitator", conn) Dim leadTbl As New DataTable conn.Open() Try adp.Fill(leadTbl) Finally conn.Close() End Try Me.ViewState("_gvs") = leadTbl Return leadTbl Case 5 'Vacation and Pers Choice Available adp.SelectCommand = New OleDbCommand("SELECT TTE_NTUSER_ID, TTE_SOCIAL_SECURITY_NBR, TTE_FNAME + ' ' + TTE_LNAME AS NAME, TTE_TOTL_VAC_AVAIL, TTE_TOTL_PERS_CHOICE_AVAIL FROM tblTCCTimeCardEmployees WHERE TTE_EMPL_STATUS = 'A' ORDER BY TTE_NTUSER_ID", conn) Dim vacPCHTbl As New DataTable conn.Open() Try adp.Fill(vacPCHTbl) Finally conn.Close() End Try Me.ViewState("_gvs") = vacPCHTbl Return vacPCHTbl Case 6 'Rates adp.SelectCommand = New OleDbCommand("SELECT TTE_NTUSER_ID, TTE_SOCIAL_SECURITY_NBR, TTE_FNAME + ' ' + TTE_LNAME AS NAME, TTE_EMPL_CATEGORY, TTE_CALC_TIMESHEET, TTE_FIVE_PCNT_RATE, TTE_TEN_PCNT_RATE FROM tblTCCTimeCardEmployees WHERE TTE_EMPL_STATUS = 'A' ORDER BY TTE_NTUSER_ID", conn) Dim rateTbl As New DataTable conn.Open() Try adp.Fill(rateTbl) Finally conn.Close() End Try Me.ViewState("_gvs") = rateTbl Return rateTbl End Select End If End Get Set(value As DataTable) Dim intRpt As Integer = Request("Report") Select Case intRpt Case 0 'Comments Try adp.SelectCommand = New OleDbCommand("SELECT CMT_REC_ID, CMT_DESCRIPTION FROM tblTSComments", conn) Dim cmdBldr As OleDbCommandBuilder = New OleDbCommandBuilder(adp) conn.Open() adp.Update(value) Catch ex As Exception 'Error during update, add code to locate error, reconcile and try again Finally conn.Close() End Try Case 1 'Teams Try adp.SelectCommand = New OleDbCommand("SELECT CT_TEAM_REC_ID, CT_TEAM_NAME, CT_REPORTS_TO FROM tblControllerTeam", conn) Dim cmdBldr As OleDbCommandBuilder = New OleDbCommandBuilder(adp) conn.Open() adp.Update(value) Catch ex As Exception 'Error during update, add code to locate error, reconcile and try again Finally conn.Close() End Try Case 2 'Status Try adp.SelectCommand = New OleDbCommand("SELECT TCS_STATUS_CODE, TCS_DESCRIPTION FROM tblEmplStatus", conn) Dim cmdBldr As OleDbCommandBuilder = New OleDbCommandBuilder(adp) conn.Open() adp.Update(value) Catch ex As Exception 'Error during update, add code to locate error, reconcile and try again Finally conn.Close() End Try Case 3 'PayPeriod Try adp.SelectCommand = New OleDbCommand("SELECT PAYPERIOD, PAYPERIODNBR, PAYPERIODLOCKED, PAYPERIODLOCKEDDATE, PAYPERIODLOCKID FROM PayPeriods ORDER BY PAYPERIOD", conn) Dim cmdBldr As OleDbCommandBuilder = New OleDbCommandBuilder(adp) conn.Open() adp.Update(value) Catch ex As Exception 'Error during update, add code to locate error, reconcile and try again Finally conn.Close() End Try Case 4 'Team Leader Try adp.SelectCommand = New OleDbCommand("SELECT OPF_NTUSER_ID, OPF_FNAME, OPF_MINIT, OPF_LNAME, OPF_REGION FROM tblOpsFacilitator", conn) Dim cmdBldr As OleDbCommandBuilder = New OleDbCommandBuilder(adp) conn.Open() adp.Update(value) Catch ex As Exception 'Error during update, add code to locate error, reconcile and try again Finally conn.Close() End Try Case 5 'Vacation and Pers Choice Available Try adp.SelectCommand = New OleDbCommand("SELECT TTE_NTUSER_ID, TTE_SOCIAL_SECURITY_NBR, TTE_FNAME + ' ' + TTE_LNAME AS NAME, TTE_TOTL_VAC_AVAIL, TTE_TOTL_PERS_CHOICE_AVAIL FROM tblTCCTimeCardEmployees WHERE TTE_EMPL_STATUS = 'A' ORDER BY TTE_NTUSER_ID", conn) Dim cmdBldr As OleDbCommandBuilder = New OleDbCommandBuilder(adp) conn.Open() adp.Update(value) Catch ex As Exception 'Error during update, add code to locate error, reconcile and try again Finally conn.Close() End Try Case 6 'Rates Try adp.SelectCommand = New OleDbCommand("SELECT TTE_NTUSER_ID, TTE_SOCIAL_SECURITY_NBR, TTE_FNAME + ' ' + TTE_LNAME AS NAME, TTE_EMPL_CATEGORY, TTE_CALC_TIMESHEET, TTE_FIVE_PCNT_RATE, TTE_TEN_PCNT_RATE FROM tblTCCTimeCardEmployees WHERE TTE_EMPL_STATUS = 'A' ORDER BY TTE_NTUSER_ID", conn) Dim cmdBldr As OleDbCommandBuilder = New OleDbCommandBuilder(adp) conn.Open() adp.Update(value) Catch ex As Exception 'Error during update, add code to locate error, reconcile and try again Finally conn.Close() End Try End Select End Set End Property Protected Sub cmdAdd_Click(sender As Object, e As System.EventArgs) Handles cmdAdd.Click rgDisplay.MasterTableView.InsertItem() End SubEnd Class