private void EnsureDDLHasValues(CascadingLookupFieldControl field) { try { field.ClearError(); int minItems = 0; try { minItems = (Convert.ToBoolean(field.strDefineNone)) ? 1 : 0; } catch { } if (field.ddlCLField.Items.Count <= minItems) { throw new Exception("No lookup results present."); } } catch (Exception ex) { field.ReportError(ex, ""); } }
void UpdateChildren(string ChildrenField) { string[] children = ChildrenField.Split(new string[] { "] " }, StringSplitOptions.RemoveEmptyEntries); Control control; foreach (string child in children) { control = FindControlRecursive(this.Page, child); if (control != null) { CascadingLookupFieldControl childField = (CascadingLookupFieldControl)control.Parent.Parent; if (childField != null) { control = FindControlRecursive(this.Page, childField.strFilterValueField); if (control != null) { DropDownList ddlFilterValueField = (DropDownList)control; PopulateChild(childField, ddlFilterValueField.SelectedValue); if (!string.IsNullOrEmpty(childField.strChildrenField)) { UpdateChildren(childField.strChildrenField); } } } } } }
void PopulateChild(CascadingLookupFieldControl field, string filterValue) { SPQuery query = BuildQuery(field.strField, field.strParentField, field.strFilterValueField, filterValue); SPListItemCollection queryResults = ExecuteQuery(field.strUrl, field.strList, field.strField, query); if (queryResults != null) { BindDDL(field, queryResults.GetDataTable(), field.strField); } }
private void BindDDL(CascadingLookupFieldControl field, DataTable dtItems, string FieldName) { InitializeDDL(field.ddlCLField, field.strDefineNone); if (dtItems != null) { DataTable dtResults = dtItems.DefaultView.ToTable(true, FieldName); BindDDL(field, dtResults.Select(), FieldName); } EnsureDDLHasValues(field); }
private void BindDDL(CascadingLookupFieldControl field, DataRow[] drRows, string FieldName) { InitializeDDL(field.ddlCLField, field.strDefineNone); if (drRows != null) { foreach (DataRow dr in drRows) { if (field.ddlCLField.Items.FindByValue(dr[FieldName].ToString()) == null) { field.ddlCLField.Items.Add(new ListItem(dr[FieldName].ToString(), dr[FieldName].ToString())); } } } EnsureDDLHasValues(field); }