I have to do a demo tomorrow and need some help here.
I have the WHDG working with four levels of nesting. I have used the drop on sql DataSources and the WHDS bound to the grid.
Selection, expansion is fine. However, I need to use my own DAL to do updates , adds and deletes.
My current issues is that although I have manged to add a new row ( can see this int he backend, ) im not sure how to refresh the grid. Here is the event I am using and my code. I need to know.
** How to update the Grid on the UI, the databind in the code below does not work, although the backend sql store is updated fine.
protected void WebHierarchicalDataGrid1_RowAdding(object sender, Infragistics.Web.UI.GridControls.RowAddingEventArgs e) { var container = (Infragistics.Web.UI.GridControls.ContainerGrid)sender;
switch (container.Level) {
case 0: //Items break;
case 1: // Hazard Risks
Model.IMdlHazard mdl = new Model.MdlHazard();
System.Exception exception = new Exception();
mdl.ItemID = int.Parse(e.Values["ItemID"].ToString()); mdl.Description = e.Values["Description"].ToString(); mdl.HazardSubCatID = int.Parse(e.Values["HazardSubCatID"].ToString()); mdl.UserName = "bp1\burntf";
DAL.DALRiskAssessment.tblHazard_Upd(ref mdl, out exception); container.DataSource = WHDS; container.DataBind(); break;
case 2 : //HazardRisks break;
case 3: //Groups Affected break; }
e.Cancel = true;
}
Actually, the answer is really simple. Turn of CRUD, handle the event and create, delete or update your row but dont cancel the event, and your grid will refresh automatically it seems !!
Nice ;-D
Hey Soberly,
Would you mind attaching your page and your code behind for the manual binding? I feel like I'm spinning my wheels as nothing I try seems to work. Thanks!
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<ig:WebDataMenu runat="server" ID="ContextMenu" IsContextMenu="true" StyleSetName="Nautilus" BorderWidth="1" BorderColor="#CCCCCC"> <ClientEvents ItemClick="MenuItem_Click" /> <Items> <ig:DataMenuItem Text="Delete Selected Row(s)" Key="Delete" /> <ig:DataMenuItem Text="Select Current Row" Key="Select" /> </Items> </ig:WebDataMenu> <div> <asp:UpdatePanel ID="updGrid" runat="server" UpdateMode="Always"> <ContentTemplate> <ig:WebHierarchicalDataGrid runat="server" AutoGenerateBands="False" AutoGenerateColumns="False" DataMember="SqlDataSource1_DefaultView" DataSourceID="WebHierarchicalDataSource1" Height="350px" DataKeyFields="TopID" Key="SqlDataSource1_DefaultView" Width="400px" onrowupdated="WebHierarchicalDataGrid1_RowUpdated" onrowupdating="WebHierarchicalDataGrid1_RowUpdating" ID="ctl45" EnableAjax="False" > <ClientEvents MouseDown="WebHierarchicalDataGridMouseDown" AJAXResponse="ctl45_ContainerGrid_AJAXResponse" /> <Columns> <ig:BoundDataField DataFieldName="TopID" Key="TopID" > <Header Text="TopID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Description" Key="Description"> <Header Text="Description" /> </ig:BoundDataField>
</Columns> <Behaviors> <ig:EditingCore> <Behaviors> <ig:CellEditing EnableInheritance="True">
<EditModeActions EnableOnActive="True" /> </ig:CellEditing> <ig:RowAdding EnableInheritance="True"> <EditModeActions MouseClick="Single" /> </ig:RowAdding> <ig:RowDeleting EnableInheritance="True" /> </Behaviors> <EditingClientEvents RowsDeleting="ctl45_Editing_RowsDeleting" /> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> <ig:Activation> <AutoPostBackFlags ActiveCellChanged="True" /> </ig:Activation> </Behaviors> </ig:WebHierarchicalDataGrid> </ContentTemplate> </asp:UpdatePanel>
</div> <ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server" oninserting="WebHierarchicalDataSource1_Inserting" onupdating="WebHierarchicalDataSource1_Updating" > <DataViews> <ig:DataView ID="SqlDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="SqlDataSource1" /> </DataViews> </ig:WebHierarchicalDataSource> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HSE_V3ConnectionString %>" DeleteCommand="DELETE FROM [tblTOP] WHERE [TopID] = @TopID" InsertCommand="INSERT INTO [tblTOP] ([Description]) VALUES (@Description)" SelectCommand="SELECT [TopID], [Description] FROM [tblTOP]" UpdateCommand="UPDATE [tblTOP] SET [Description] = @Description WHERE [TopID] = @TopID"> <DeleteParameters> <asp:Parameter Name="TopID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Description" Type="String" /> <asp:Parameter Name="TopID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Description" Type="String" /> </InsertParameters> </asp:SqlDataSource>
</asp:Content>
Thanks! Can you attach the code behind? I also want to see how you're handling the manual binding.
For example, this is what I do to add rows.
mdl.ItemID = int.Parse(e.Values["ItemID"].ToString()); mdl.Description = e.Values["Description"].ToString(); mdl.HazardSubCatID = int.Parse(e.Values["HazardSubCatID"].ToString()); mdl.UserName = "DP1\UserName";
DAL.DALRiskAssessment.tblHazard_Upd(ref mdl, out exception);
break;
// e.Cancel = true;
} }