cjard,
The idea you posted pointed me in the right direction. It took a little more work to deal with walking the control tree to get this working properly but now my library is proud owner to a new routine which will be very useful.
Using that routine in my library now enables me to populate the "control array" I have set up in the following fashion, exactly what I had in mind.Code:/// <summary> /// Web Version: /// /// Builds a dictionary containing the references to all controls in the specified controls /// container so they can be referenced by constructed string names. This provides the ability /// to build sections of controls and reference them similarly to the way they could have been /// with control arrays back in the VB6 days. /// </summary> /// <param name="container">Object containing the controls to be discovered.</param> /// <param name="list">Dictionary into which the references should be placed.</param> /// public void BuildControlList(System.Web.UI.ControlCollection container, Dictionary<string, System.Web.UI.Control> list) { foreach (System.Web.UI.Control c in container) { // // If the current control has a set of controls, recurse and scan the collection. // if (c.Controls.Count > 0) BuildControlList(c.Controls, list); // // If this is a leaf node in the controls collection, record its reference in the // dictionary if its ID is not null. // else { if (c.ID != null) list[c.ID] = c; } } }
Works perfectly. Thanks for your feedback.Code:// // There will be up to 5 categories to list. // string key = ""; // Use to build the control names to reference. for (int i = 0; i < catList.Count; ++i) { var CLR = (CategoryLedgerRecord) catList[i]; key = "cboCat" + (i+1).ToString(); ((DropDownList) cList[key]).Text = CLR.CategoryName; key = "txtAmount" + (i+1).ToString(); ((TextBox) cList[key]).Text = CLR.Amount.ToString(); key = "txtComment" + (i+1).ToString(); ((TextBox) cList[key]).Text = CLR.Comments; }
-Max




Reply With Quote