Update on Grid fails?
-
I don't understand this one... Almost everything works except the Update on the grid: Delete, Cancel, Edit* If I take the Load_Grid out of m_dgIDs.EditCommand--I have to click the Edit link twice for it to turn into a textbox that I can edit, but the original content is not there. If I leave the Load_Grid in the EditCommand, the textbox will appear immediately with the cell's content and I can edit it. HOWEVER, the grid no longer appears to be bound and this line blows up: Dim id As Integer = CType(e.Item.Cells(0).Text, Integer) e.Item.Cells(0).Text is = "" or nothing I tried to keep this code to a MIMIMUM because I know it is a lot to ask of forum members, but if someone has the time, I would appreciate any thoughts on the subject. Thanks - A Lot. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then Load_DropDown() End If End Sub Private Sub m_ddFacility_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_ddFacility.SelectedIndexChanged Load_Grid() End Sub Private Sub dgIDs_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.UpdateCommand 'ID is just a simple class that interfaces with the database & has 3 properties 'CostCenterID, FacilityID, & Description...pretty trivial Dim oCostCenter As New ID Dim id As Integer = CType(e.Item.Cells(0).Text, Integer) oCostCenter.Load(id) oCostCenter.Description = CType(e.Item.Cells(2).Text, String) oCostCenter.FacilityID = m_ddFacility.SelectedValue oCostCenter.Update() Load_Grid() m_dgIDs.EditItemIndex = -1 End Sub Private Sub dgIDs_Edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.EditCommand m_dgIDs.EditItemIndex = e.Item.ItemIndex Load_Grid() End Sub Private Sub dgIDs_Delete(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.DeleteCommand Dim oCostCenter As New ID Dim id As Integer = CType(e.Item.Cells(0).Text, Integer) oCostCenter.Load(id) oCostCenter.Delete() Load_Grid() End Sub Private Sub dgIDs_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.CancelCommand m_dgIDs.EditItemIndex = -1 Load_Grid() End Sub Private Sub Load_Grid() Dim ds As DataSet Dim oData_Dev As New CFormData("DefaultConnectionString") ds = oData_Dev.GetDataSet("SELECT * FROM CostCenter WHERE FacilityID =
-
I don't understand this one... Almost everything works except the Update on the grid: Delete, Cancel, Edit* If I take the Load_Grid out of m_dgIDs.EditCommand--I have to click the Edit link twice for it to turn into a textbox that I can edit, but the original content is not there. If I leave the Load_Grid in the EditCommand, the textbox will appear immediately with the cell's content and I can edit it. HOWEVER, the grid no longer appears to be bound and this line blows up: Dim id As Integer = CType(e.Item.Cells(0).Text, Integer) e.Item.Cells(0).Text is = "" or nothing I tried to keep this code to a MIMIMUM because I know it is a lot to ask of forum members, but if someone has the time, I would appreciate any thoughts on the subject. Thanks - A Lot. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then Load_DropDown() End If End Sub Private Sub m_ddFacility_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_ddFacility.SelectedIndexChanged Load_Grid() End Sub Private Sub dgIDs_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.UpdateCommand 'ID is just a simple class that interfaces with the database & has 3 properties 'CostCenterID, FacilityID, & Description...pretty trivial Dim oCostCenter As New ID Dim id As Integer = CType(e.Item.Cells(0).Text, Integer) oCostCenter.Load(id) oCostCenter.Description = CType(e.Item.Cells(2).Text, String) oCostCenter.FacilityID = m_ddFacility.SelectedValue oCostCenter.Update() Load_Grid() m_dgIDs.EditItemIndex = -1 End Sub Private Sub dgIDs_Edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.EditCommand m_dgIDs.EditItemIndex = e.Item.ItemIndex Load_Grid() End Sub Private Sub dgIDs_Delete(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.DeleteCommand Dim oCostCenter As New ID Dim id As Integer = CType(e.Item.Cells(0).Text, Integer) oCostCenter.Load(id) oCostCenter.Delete() Load_Grid() End Sub Private Sub dgIDs_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles m_dgIDs.CancelCommand m_dgIDs.EditItemIndex = -1 Load_Grid() End Sub Private Sub Load_Grid() Dim ds As DataSet Dim oData_Dev As New CFormData("DefaultConnectionString") ds = oData_Dev.GetDataSet("SELECT * FROM CostCenter WHERE FacilityID =