Hi
I am Ultrawebgrid into WebHierarchicalDataGrid. Here is my code.
<ig:WebHierarchicalDataGrid ID="gvCostCenters" runat="server" InitialDataBindDepth="0" Key="Parent" AutoGenerateColumns="false" AutoGenerateBands="false" DataKeyFields="CC_ID" Height="600" Width="500" OnInitializeRow="gvCostCenters_InitializeRow1"> <Columns> <ig:UnboundField Key="Notes" Width="30px" Footer-Text="..."> <Header Text="Notes" /> </ig:UnboundField> <ig:BoundDataField DataFieldName="MI_YEAR" Key="MI_YEAR " Header-Text="Year" Hidden="true" /> <ig:BoundDataField DataFieldName="CC_NUM" Key="CC_NUM" Header-Text="Number" /> <ig:BoundDataField DataFieldName="CC_NAME" Key="CC_NAME" Header-Text="Name" Hidden="false" /> <ig:BoundDataField DataFieldName="CC_ID" Key="CC_ID" Header-Text="CC_ID" Hidden="True" /> <ig:BoundDataField DataFieldName="NO_MGT" Key="NO_MGT " Header-Text="Mgt" /> <ig:BoundDataField DataFieldName="NO_STAFF" Key="NO_STAFF" Header-Text="Staff" /> <ig:BoundDataField DataFieldName="TOTAL" Key="TOTAL" Header-Text="Total" /> <ig:BoundDataField DataFieldName="CHILDROWS" Key="CHILDROWS" Header-Text="" Hidden="true" /> <ig:BoundDataField DataFieldName="NUM_NOTES" Key="NUM_NOTES" Header-Text="" Hidden="true" /> <ig:BoundDataField DataFieldName="NUM_CHILD" Key="NUM_CHILD" Header-Text="" Hidden="true" /> <ig:BoundDataField DataFieldName="MI_ID" Key="MI_ID" Header-Text="" Hidden="true" /> </Columns> <Bands> <ig:Band Key="CC_ID" AutoGenerateColumns="false" DataKeyFields="CC_ID" DataMember="" > <Columns> <ig:BoundDataField DataFieldName="EMP_NUM" Key="EMP_NUM" Header-Text="Emp #" /> <ig:BoundDataField DataFieldName="EMP_NAME" Key="EMP_NAME" Header-Text="Employee Name" /> <ig:BoundDataField DataFieldName="CM_ID" Key="CM_ID" Hidden="true" /> <ig:BoundDataField DataFieldName="CC_ID" Key="CC_ID" Header-Text="Emp #" /> <ig:BoundDataField DataFieldName="EMP_TITLE" Key="EMP_TITLE" Header-Text="Title" /> <ig:BoundDataField DataFieldName="FTE" Key="FTE" Hidden="true" Header-Text="FTE" /> <ig:BoundDataField DataFieldName="EMP_MORS" Key="EMP_MORS" Header-Text="M/S" /> <ig:UnboundField Key="Notes" Width="30px" Footer-Text="..."> <Header Text="Adj" /> </ig:UnboundField> <ig:BoundDataField DataFieldName="NUM_DISTRIBUTION" Key="NUM_DISTRIBUTION" Hidden="true" /> </Columns> </ig:Band> </Bands><Behaviors> <ig:EditingCore> <Behaviors> <ig:CellEditing Enabled="true" EditModeActions-EnableF2="true"> <ColumnSettings></ColumnSettings> </ig:CellEditing> </Behaviors> </ig:EditingCore> </Behaviors> </ig:WebHierarchicalDataGrid>
and the codebehind is like..
Boolean exportCC = false; DataSet costAccounts; EffortDistributionService svc; List<string> msgs = new List<string>();
protected void Page_Load(object sender, EventArgs e) { try { currentPage = "EffortDistribution"; if (currentMI.modelInstanceID == Guid.Empty || currentMM.MM_P_OR_F_OR_T == "P") { Response.Redirect("Default.aspx"); return; }
if (isInRole("Client")) { btnImport.Visible = false; btnImportCM.Visible = false; FileUpload1.Visible = false; btnExportFTE.Visible = false; if (!isInRole("ClientAdmin")) { btnQuery.Visible = false; } } if (currentMM.MM_P_OR_F_OR_T == "F") { btnExportFTE.Visible = false; btnAddFTE.Visible = false; }
if (currentMM.readOnlyClient) { btnImport.Enabled = false; btnImportCM.Enabled = false; FileUpload1.Enabled = false; btnAddFTE.Disabled = true; } svc = new EffortDistributionService(); if (!Page.IsPostBack) { int numYears = svc.getNumPreviousYears(this.currentMI.modelInstanceID); ddlYears.Items.Clear(); if (numYears > 5) { numYears = 5; } for (int i = 1; i <= numYears + 1; i++) { ddlYears.Items.Add(i.ToString()); }
ddlYears.SelectedValue = "1"; } hdnLastEdit.Value = currentMM.MM_LAST_EDIT.ToString();
costAccounts = svc.getCostCenters(this.currentMI.modelInstanceID, ddlYears.SelectedValue); if (costAccounts.Tables[0].Rows.Count > 0) { DataRow[] childRows = costAccounts.Tables[0].Select("CHILDROWS > 0"); if (childRows.Length > 0) { string str_cc_id = childRows[0].ItemArray[3].ToString(); costAccounts.Tables[1].Merge(svc.getCostCenterChildren(new Guid(str_cc_id), currentMI.modelInstanceID).Tables[0]); //DataSet costAccounts = svc.getCostCenters(rb, ddlYears.SelectedValue); // TODO - delete this line DataColumn parentColumn = costAccounts.Tables[0].Columns["CC_ID"]; DataColumn childColumn = costAccounts.Tables[1].Columns["CC_ID"]; DataRelation relExpenseDistribution; relExpenseDistribution = new DataRelation("CostCenterMembers", parentColumn, childColumn); costAccounts.Relations.Add(relExpenseDistribution); } gvCostCenters.DataSource = costAccounts; gvCostCenters.DataBind();
} } catch (Exception exp) { logutils.createExceptionLogEntry(exp, loggedInUserID); Response.Write("<script>alert('An error occurred loading the Effort Distribution Screen.');</script>"); if (this.currentMI.modelType == null) msgs.Add("Most likely this occurred because an active client related identifier was not passed."); } finally { if (svc != null) { svc.Dispose(); } } }
and in InitializeRow it is like
protected void gvCostCenters_InitializeRow1(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { int level = Convert.ToInt32(((Infragistics.Web.UI.GridControls.ContainerGridRecord)(e.Row)).Level); if (level == 0) { //If change has been made to the child records (based on count in column 6 > 0), add * to end of ST_NUM if (Convert.ToInt32(e.Row.Items[8].Text) > 0) { if (Convert.ToInt32(e.Row.Items[10].Text) > 0 && e.Row.Items[2].ToString().IndexOf("*") == -1) e.Row.Items[2].Text = e.Row.Items[2].Text + "*";
} if (Convert.ToInt32(e.Row.Items[9].Text) > 0) e.Row.Items[0].Text = "!";
//If row is expanded, load the child records and rebind the dataset if (Convert.ToInt32(e.Row.Items[8].Text) > 0 )//&& e.Row.Expanded == true) //on sort, e.row.expanded might be referring to a different row... { String cc_id = e.Row.Items[4].Text;// ToString(); int count; count = costAccounts.Tables[1].Select("CC_ID='" + cc_id + "'").Length; if (count == 0) { DataSet childrows = svc.getCostCenterChildren(new Guid(cc_id), new Guid(e.Row.Items[11].Text.ToString())); costAccounts.Tables[1].Merge(childrows.Tables[0]);
gvCostCenters.DataSource = costAccounts; gvCostCenters.DataBind();
} } } else { //If change has been made to the child records (based on count in column 6 > 0), add * to end of ST_NUM if (Convert.ToInt32(e.Row.Items[8].Text)> 0 && e.Row.Items[1].ToString().IndexOf("*") == -1) { e.Row.Items[1].Text = e.Row.Items[1].Text + "*";
} }
}
How can I make the child grid to populate as it is not populating currently.What am I missing? Please guide me.
I have also attached a screenshot.How to set datamember for childband?
This is my Ultrawebgrid's javascript code. How can I know the level of child band as indiacated in Bold in the If condition for Webhierarchicaldatagrid?
var CC_ID; var CM_ID = "NULL"; var YEAR; var MI_ID; if (igtbl_getRowById(rowId).Band.Index == 0) { CC_ID = igtbl_getRowById(rowId).getCell(4).getValue(); YEAR = igtbl_getRowById(rowId).getCell(1).getValue(); MI_ID = igtbl_getRowById(rowId).getCell(11).getValue(); } else if (igtbl_getRowById(rowId).Band.Index == 1) { CM_ID = igtbl_getRowById(rowId).getCell(2).getValue(); CC_ID = igtbl_getRowById(rowId).ParentRow.getCell(4).getValue(); YEAR = igtbl_getRowById(rowId).ParentRow.getCell(1).getValue(); MI_ID = igtbl_getRowById(rowId).ParentRow.getCell(11).getValue(); } window.frames[0].document.location = "EffortDistributionDetail.aspx?CC_ID=" + CC_ID + "&CM_ID=" + CM_ID + "&YEAR=" + YEAR + "&MI_ID=" + MI_ID;}
Hello,
I have attached a sample for you in order to show you how to correctly configure a data source and WebHierarchicalDataGrid bind to it, with all DataMembers and Keys set.
About your question, how to get the child band level, currently it is not possible to get it "on the client", although it is possible to get it "on the server" for example if you handle InitializeRow server event:
protected void WebHierarchicalDataGrid1_InitializeRow(object sender, RowEventArgs e){ int level = ((Infragistics.Web.UI.GridControls.ContainerGridRecord)(e.Row)).Level;
if (level == 0) { // Parent records
} else { // Child records
}}
Hi on going through the attachment you sent me I got the error
"Runtime Exception: No child grid scripts descriptors are available "
How can I use "row.Expanded" in initializeRow in WebHierarchicalDataGrid?
I am attaching the sample again with little more modifications.
You can use Expanded as a getter and setter. For example if you set Expanded to be true, the row will expand. Have a look at the attached sample where I am implementing this.
Code snippet:
protected void WebHierarchicalDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { ((ContainerGridRecord)e.Row).Expanded = true; }