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?
what was the workaround?
Hello Alan,
I am glad you managed to resolve the issue.
Please let me know if you have any other questions.
Yeah, that code would throw an exception. I figured out a workaround.
You could use the casting you suggested. The code should look like the following:
For i = 0 To Me.wgrdTODtls.Rows.Count - 1
intConsequence = CInt(Me.wgrdTODtls.Rows(i).Items(6).Text)
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.
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?