Hello,
This question relates to IG version 10.3.20103.2134.
All the examples that I can find in the forums which use Delete functionality of the grid all use embedded datasources in their html markup. Due to security concerns, I am not able to do that. I bind the grid to a datasource in code behind just fine.
I implement the delete on the client side via:
function DeleteRow() { var grid = $find('<%= wgAgendaItems.ClientID %>'); var gridRows = grid.get_rows(); var selectedRows = grid.get_behaviors().get_selection().get_selectedRows(); for (var i = selectedRows.get_length() - 1; i >= 0; i--) { var row = selectedRows.getItem(i); gridRows.remove(row); } }
From what I can tell in the debugger, there are no script errors.
Here is the templated column in the grid:
<ig:TemplateDataField Key="DeleteItem" Width="80px"> <ItemTemplate> <asp:ImageButton ID="DeleteItem" ImageUrl="~/Images/icon_delete.gif" runat="server" AlternateText="Delete Icon" ToolTip="Delete Agenda Item" OnClientClick="DeleteRow(); return false;"/> </ItemTemplate></ig:TemplateDataField>
When this function runs I get an error and my code behind code which can actually perform the delete never gets called. The error is attached in a screen shot.
If anyone has a full example with binding to a collection of objects via code behind could you share?
Hello Alan,
Thank you for posting in the community.
I have been looking into the behavior that you have described and I suggest that you make sure you bind the grid to the data source on every postback by calling the DataBind() method, in order to ensure that the grid is databound in time for row deletion.
I’m attaching the sample I created.
Please let me know if you have any further questions.
Hi Alan,
Please let me know if you have any further questions on the matter.
I suggest that you modify your SaveSequence method like in the following code sample:
Public Sub SaveConsequence() Dim i As Integer Dim strOrgCode As String Dim strEmplId As String Dim strFyCd As String Dim intPdNo As Integer Dim intConsequence As Integer If Me.wgrdTODtls.Rows.Count > 0 Then For i = 0 To Me.wgrdTODtls.Rows.Count - 1 intConsequence = CInt(DirectCast(Me.wgrdTODtls.Rows(0).DataItem, IGDataGridNoAutoCRUD.TODetails).Consequence) If intConsequence >= 0 Then strOrgCode = DirectCast(Me.wgrdTODtls.Rows(0).DataItem, IGDataGridNoAutoCRUD.TODetails).OrgCode.ToString().Trim strEmplId = DirectCast(Me.wgrdTODtls.Rows(0).DataItem, IGDataGridNoAutoCRUD.TODetails).Empl_Id.ToString().Trim strFyCd = DirectCast(Me.wgrdTODtls.Rows(0).DataItem, IGDataGridNoAutoCRUD.TODetails).Fy_Cd.ToString().Trim intPdNo = DirectCast(Me.wgrdTODtls.Rows(0).DataItem, IGDataGridNoAutoCRUD.TODetails).Pd_No.ToString().Trim End If Next End If End Sub
Please let me know if this helps.
While I realize that the code on the save routine was not cast correctly (I realized that last week), the issue is more fundamental than that. After setting some break points in the page load event, I realized that the post back is wiping out the contents of the grid. So, it is like I need to experiment with the view state of the grid or somehow persist the values back to the grid (including the user's edits). If you have advice of best practices along this line, it would be appreciated.
I am not getting that to cast correctly. This will throw an 'invalid cast' exception:
CType(Me.wgrdTODtls.Rows(i).DataItem, TODetails)
as does your example:
DirectCast(Me.wgrdTODtls.Rows(i).DataItem, IGDataGridNoAutoCRUD.TODetails).
But at least I can do this without an exception, but I am not happy with having to do it this way. Maybe you could correct the casting?
intConsequence = CInt(Me.wgrdTODtls.Rows(i).Items(6).Text)
You could use the casting you suggested. The code should look like the following:
For i = 0 To Me.wgrdTODtls.Rows.Count - 1
If intConsequence >= 0 Then
strOrgCode = Me.wgrdTODtls.Rows(i).Items(9).Text
strEmplId = Me.wgrdTODtls.Rows(i).Items(10).Text
strFyCd = Me.wgrdTODtls.Rows(i).Items(7).Text
intPdNo = CInt(Me.wgrdTODtls.Rows(i).Items(8).Text)
End If
Next
If you have any other questions please feel free to contact me.
Yeah, that code would throw an exception. I figured out a workaround.
what was the workaround?
I am glad you managed to resolve the issue.
Please let me know if you have any other questions.