I have a dataset, obtained from a webservice which contains 2 tables (a parent and child). I am presently binding it to the webhierarchicaldata grid. I presently have a bound checkbox column from the child table which the user can change. To update the source data, I need to send the webservice the changes from the dataset (via the GetChanges dataset method). How can I obtain which child rows have been changed on the server side (after user clicks an ASP button - Save)?
Thanks,
Hung
Hello,
You can handle the RowUpdating event (or each other event corresponding to a CRUD operation - RowAdding, RowDeleting) and get this information from the event argument. Since e.Row will return references to the edited rows from both the parent and child bands, you can check the Level of the row (0 corresponds to parent, 1 corresponds to 1st level child and so on) and if the row comes from a child band you can add it to a list like this:
List rows = new List();if (((ContainerGridRecord)e.Row).Level == 1) { rows.Add(e.Row); }
You can also get e.Values to get collection of the updated values for the row.
I hope this helps. If you have any further questions, please do not hesitate to contact me, I will be glad to help.
So I added the following on my code behind, but if I put a breakpoint on it, I notice it does not fire. What other changes could be needed?
Private Sub WebHierarchicalDataGrid1_RowUpdating(sender As Object, e As Infragistics.Web.UI.GridControls.RowUpdatingEventArgs) Handles WebHierarchicalDataGrid1.RowUpdating
'Dim rows As New List()
If DirectCast(e.Row, ContainerGridRecord).Level = 1 Then
'rows.Add(e.Row)
End If
End Sub
From ASP Page:
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="350px"
Width="100%" DataKeyFields="RoleID" DataMember="Parent" AutoGenerateBands="false"
AutoGenerateColumns="False" >
<Columns>
<%
-- <ig:BoundDataField Key="ID" DataFieldName="ID">
<Header Text="ID" />
</ig:BoundDataField>--
%>
<ig:BoundDataField Key="RoleID" DataFieldName="RoleID">
</ig:BoundDataField>
<ig:BoundDataField Key="Name" DataFieldName="Name">
<Header Text="Name" />
</Columns>
<Bands>
<ig:Band Key="ChildBand_0" DataKeyFields="RoleID,PRODUCT_CATEGORY_ID" DataMember="Child"
AutoGenerateColumns="False">
<ig:BoundDataField Key="PRODUCT_CATEGORY_ID" DataFieldName="PRODUCT_CATEGORY_ID">
<Header Text="PRODUCT_CATEGORY_ID" />
<ig:BoundCheckBoxField DataFieldName="ALLOW_FLAG" Key="ALLOW_FLAG" >
<Header Text="Permit" />
</ig:BoundCheckBoxField>
<ig:BoundDataField DataFieldName="SORT_ORDER_CODE" Key="SORT_ORDER_CODE" Hidden="true">
<Behaviors>
<ig:EditingCore >
<ig:CellEditing>
<ColumnSettings>
--<ig:EditingColumnSetting ColumnKey="ID" ReadOnly="true" />--%>
<ig:EditingColumnSetting ColumnKey="RoleID" ReadOnly="true" />
<ig:EditingColumnSetting ColumnKey="PRODUCT_CATEGORY_ID" ReadOnly="true" />
<ig:EditingColumnSetting ColumnKey="ALLOW_FLAG" />
<ig:EditingColumnSetting ColumnKey="SORT_ORDER_CODE" ReadOnly="true" />
</ColumnSettings>
<EditModeActions MouseClick="Single" />
</ig:CellEditing>
</Behaviors>
</ig:EditingCore>
</ig:Band>
</Bands>
</ig:WebHierarchicalDataGrid>
You need to hook the grid to the event handler by adding OnRowUpdating="WebHierarchicalDataGrid1_RowUpdating":
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="350px"Width="100%" DataKeyFields="RoleID" DataMember="Parent" AutoGenerateBands="false"AutoGenerateColumns="False"OnRowUpdating="WebHierarchicalDataGrid1_RowUpdating" >
Please let me know if this helps.
Unfortunately it still does not fire. ASP pages tells me 'Can not access Private Sub 'WebHierarchicalDataGrid_RowUpdating' here.' for the OnRowUpdating. I can change it to Public and the error is removed (but still does not fire).
Could you post a small example in which it works (vb.net code behind)?
Thanks.
In VB the code snippet I suggested should look like this:
Dim rows As New List(Of ContainerGridRecord)
Protected Sub WebHierarchicalGrid1_RowUpdating(sender As Object, e As RowUpdatingEventArgs) Handles whdg.RowUpdating
rows.Add(e.Row)
Please refer to the sample attached. Please note that I am using this with BatchUpdating enabled.
Thanks for the sample. I've created a new project and added the samples provided. Unfortunately I can not compile it, it presently tells me in the code behind...
'whdg' is not declared. It may be inaccessible due to its protection level.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
whdg.DataSource = populateDataSet()
whdg.DataBind()
Also should mention this error appears as well...
Error 7 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
Protected Sub whdg_RowUpdating(sender As Object, e As RowUpdatingEventArgs) Handles whdg.RowUpdating
Dim vals = e.Values.ToString()
Hello,If you need any further assistance on the issue, please feel free to contact me, I will be glad to help you.
There were some issues because of the previous conversion of the sample (project to website and vice versa). I modified it and now the RowUpdating event fires correctly and the error it used to receive is now gone (Error 7 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.)
I hope this helps.
Thank you for choosing Infragistics components !
It is a VS2010 project running .NET 4.0
I have looked at that and it fires for me. Can you just attach the latest version of the project so we can be sure that we are working on the same things?
Thank you.
Thanks, that removed the error and allowed me to run the code. However, if I place a breakpoint on whdg_RowUpdating, I never see it fire. I am checking and unchecking the checkboxes.