/// <summary> /// Handles the UpdateCommand event of the grdSelectionValues control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void grdSelectionValues_Update(object source, DataGridCommandEventArgs e) { lblError.Text = String.Empty; if (ListItemType.EditItem == e.Item.ItemType) { var selectionName = (TextBox)e.Item.FindControl("txtEditSelectionName"); var txtValue = (TextBox)e.Item.FindControl("txtEditSelectionValue"); if (selectionName != null && txtValue != null) { var customFieldSelectionId = (int)((DataGrid)source).DataKeys[e.Item.ItemIndex]; UserCustomFieldSelection cfs = UserCustomFieldSelectionManager.GetById(customFieldSelectionId); cfs.Name = selectionName.Text.Trim(); cfs.Value = txtValue.Text.Trim(); UserCustomFieldSelectionManager.SaveOrUpdate(cfs); lblError.Text = String.Empty; foreach (DataGridItem item in grdCustomFields.Items) { var grdSelectionValues = (DataGrid)item.FindControl("grdSelectionValues"); if (null == grdSelectionValues) { continue; } grdSelectionValues.ShowFooter = true; grdSelectionValues.EditItemIndex = -1; BindCustomFieldSelections(); } } ViewState["EditingSubGrid"] = null; BindCustomFields(); } }
/// <summary> /// Handles the ItemCommand event of the grdSelectionValues control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void grdSelectionValues_ItemCommand(object source, DataGridCommandEventArgs e) { UserCustomFieldSelection cfs; var itemIndex = e.Item.ItemIndex; int itemId; var grid = source as DataGrid; switch (e.CommandName) { case "up": //move row up if (itemIndex == 0) { return; } itemId = Convert.ToInt32(grid.DataKeys[itemIndex]); cfs = UserCustomFieldSelectionManager.GetById(itemId); cfs.SortOrder -= 1; UserCustomFieldSelectionManager.SaveOrUpdate(cfs); break; case "down": //move row down if (itemIndex == grid.Items.Count - 1) { return; } itemId = Convert.ToInt32(grid.DataKeys[itemIndex]); cfs = UserCustomFieldSelectionManager.GetById(itemId); cfs.SortOrder += 1; UserCustomFieldSelectionManager.SaveOrUpdate(cfs); break; case "add": if (Page.IsValid) { var txtAddSelectionName = (TextBox)e.Item.FindControl("txtAddSelectionName"); var txtAddSelectionValue = (TextBox)e.Item.FindControl("txtAddSelectionValue"); cfs = new UserCustomFieldSelection { CustomFieldId = Convert.ToInt32(e.CommandArgument), Name = txtAddSelectionName.Text.Trim(), Value = txtAddSelectionValue.Text.Trim() }; UserCustomFieldSelectionManager.SaveOrUpdate(cfs); } break; } BindCustomFieldSelections(); }
protected void btnDeleteSelectionValue_Click(object sender, ImageClickEventArgs e) { var btn = sender as ImageButton; if (btn == null) { return; } var id = btn.CommandArgument.To <int>(); if (!UserCustomFieldSelectionManager.Delete(id)) { lblError.Text = LoggingManager.GetErrorMessageResource("DeleteCustomFieldError"); } else { BindCustomFields(); } }
protected void rptCustomFields_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) { return; } var currentField = (UserCustomField)e.Item.DataItem; var ph = (PlaceHolder)e.Item.FindControl("PlaceHolder"); var id = (HiddenField)e.Item.FindControl("Id"); var name = (HiddenField)e.Item.FindControl("Name"); id.Value = currentField.Id.ToString(); name.Value = currentField.Name; switch (currentField.FieldType) { case CustomFieldType.DropDownList: var ddl = new DropDownList { ID = FIELD_VALUE_NAME, DataSource = UserCustomFieldSelectionManager.GetByCustomFieldId(currentField.Id), DataTextField = "Name", DataValueField = "Value", CssClass = "form-control" }; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("-- Select One --", string.Empty)); ddl.SelectedValue = currentField.Value; ph.Controls.Add(ddl); if (IsLocked) { ddl.Enabled = false; } break; case CustomFieldType.Date: var fieldValue1 = new TextBox(); fieldValue1.Attributes.Add("bn-data-type", "date"); var cal = new CalendarExtender(); var img = new Image { ID = "calImage", CssClass = "icon", ImageUrl = "~/images/calendar.gif" }; cal.PopupButtonID = "calImage"; cal.TargetControlID = FIELD_VALUE_NAME; cal.ID = "Calendar1"; fieldValue1.ID = "FieldValue"; fieldValue1.Width = 80; ph.Controls.Add(fieldValue1); ph.Controls.Add(img); ph.Controls.Add(new LiteralControl(" ")); DateTime dt; var dateTimeValue = currentField.Value; if (DateTime.TryParse(dateTimeValue, out dt)) { dateTimeValue = dt.ToShortDateString(); } fieldValue1.Text = dateTimeValue; ph.Controls.Add(cal); if (IsLocked) { cal.Enabled = false; fieldValue1.Enabled = false; img.Visible = false; } break; case CustomFieldType.Text: var fieldValue = new TextBox { ID = FIELD_VALUE_NAME, Text = currentField.Value, CssClass = "form-control" }; fieldValue.Attributes.Add("bn-data-type", "text"); ph.Controls.Add(fieldValue); if (currentField.Value.Trim().ToLower().StartsWith("http")) { var url = new HyperLink { Target = "_blank", NavigateUrl = currentField.Value, Text = " GOTO >>" }; ph.Controls.Add(url); } if (IsLocked) { fieldValue.Enabled = false; } break; case CustomFieldType.YesNo: var chk = new CheckBox { ID = FIELD_VALUE_NAME }; if (!String.IsNullOrEmpty(currentField.Value)) { chk.Checked = Boolean.Parse(currentField.Value); } ph.Controls.Add(new LiteralControl("<div class=\"checkbox\">")); ph.Controls.Add(chk); ph.Controls.Add(new LiteralControl("</div>")); if (IsLocked) { chk.Enabled = false; } break; case CustomFieldType.RichText: var editor = new HtmlEditor { ID = FIELD_VALUE_NAME }; editor.Attributes.Add("bn-data-type", "html"); ph.Controls.Add(editor); editor.Text = currentField.Value; break; case CustomFieldType.UserList: ddl = new DropDownList { ID = FIELD_VALUE_NAME, DataSource = UserManager.GetAllUsers(), DataTextField = "DisplayName", DataValueField = "UserName", CssClass = "form-control" }; ddl.DataBind(); ddl.Items.Insert(0, new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectOne").ToString(), string.Empty)); ddl.SelectedValue = currentField.Value; ph.Controls.Add(ddl); if (IsLocked) { ddl.Enabled = false; } break; } var lblFieldName = (Label)e.Item.FindControl("lblFieldName"); lblFieldName.AssociatedControlID = FIELD_VALUE_NAME; lblFieldName.Text = currentField.Name; if (EnableValidation) { //if required dynamically add a required field validator if (currentField.Required && currentField.FieldType != CustomFieldType.YesNo) { var valReq = new RequiredFieldValidator { ControlToValidate = FIELD_VALUE_NAME, Text = string.Format(" ({0})", GetGlobalResourceObject("SharedResources", "Required")).ToLower(), Display = ValidatorDisplay.Dynamic, CssClass = "text-danger validation-error", SetFocusOnError = true }; if (currentField.FieldType == CustomFieldType.DropDownList) { valReq.InitialValue = string.Empty; } ph.Controls.Add(valReq); } //create data type check validator if (currentField.FieldType != CustomFieldType.YesNo) { var valCompare = new CompareValidator { Type = currentField.DataType, Text = String.Format("({0})", currentField.DataType), Operator = ValidationCompareOperator.DataTypeCheck, Display = ValidatorDisplay.Dynamic, ControlToValidate = FIELD_VALUE_NAME }; ph.Controls.Add(valCompare); } } }
/// <summary> /// Gets the custom field selections. /// </summary> /// <param name="customFieldId">The custom field id.</param> /// <returns></returns> private static List <UserCustomFieldSelection> GetCustomFieldSelections(int customFieldId) { return(UserCustomFieldSelectionManager.GetByCustomFieldId(customFieldId)); }