hi I am bindig custom controls(tradextbox,radadateinput vs.)on runtime on a grid.And After post i wantto got values from the custom columns..
the code for creating control snippet like this
and
if i bind grid every page_load event of page,
when i want to take values that entered into this custom controls ,it does resets values.
and if i only bind grid once at pagepostback
when i want to take values over the controls it return null referance...
what's wrong with this code?
and how can i bind controls on grid dynamically and got values entered to them ?
the code for creating control snippet like this
| private void CreateCustomControl(TableCell templateControl, Property property) |
| { |
| switch (property.UiType) |
| { |
| case "RadTextBox": |
| #region |
| RadTextBox radTextBox1 = new RadTextBox(); |
| radTextBox1.ID = string.Format("RadTextBox_{0}", property.Id); |
| if(!IsPostBack)radTextBox1.Text = property.DefaultValue; |
| if (property.MaxLength != null) |
| { |
| radTextBox1.MaxLength = (int)property.MaxLength; |
| } |
| templateControl.Controls.Add(radTextBox1); |
| #endregion |
| break; |
| case "MultilineRadTextBox": |
| #region |
| RadTextBox radTextBox2 = new RadTextBox(); |
| radTextBox2.ID = string.Format("MultilineRadTextBox_{0}", property.Id); |
| radTextBox2.TextMode = InputMode.MultiLine; |
| if (!IsPostBack) radTextBox2.Text = property.DefaultValue; |
| if (property.MaxLength != null) |
| { |
| radTextBox2.MaxLength = (int)property.MaxLength; |
| } |
| templateControl.Controls.Add(radTextBox2); |
| #endregion |
| break; |
| case "NumericTextBox": |
| #region |
| RadNumericTextBox radNumericTextBox = new RadNumericTextBox(); |
| radNumericTextBox.ID = string.Format("NumericTextBox_{0}", property.Id); |
| if (!IsPostBack) radNumericTextBox.Value = !string.IsNullOrEmpty(property.DefaultValue) ? double.Parse(property.DefaultValue) : (double)0; |
| radNumericTextBox.MaxValue = (double)property.MaxValue; |
| radNumericTextBox.MinValue = (double)property.MinValue; |
| templateControl.Controls.Add(radNumericTextBox); |
| #endregion |
| break; |
| case "RadDateInput": |
| #region |
| RadDateInput radDatePicker = new RadDateInput(); |
| radDatePicker.ID = string.Format("RadDateInput_{0}", property.Id); |
| radDatePicker.ReadOnly = true; |
| if (!string.IsNullOrEmpty(property.DefaultValue)) |
| { |
| if (!IsPostBack) radDatePicker.SelectedDate = Convert.ToDateTime(property.DefaultValue); |
| } |
| templateControl.Controls.Add(radDatePicker); |
| #endregion |
| break; |
| case "RadComboBox": |
| #region |
| RadComboBox radComboBox = new RadComboBox(); |
| radComboBox.ID = string.Format("RadComboBox_{0}", property.Id); |
| string[] options = property.Options.Split('#'); |
| string[] optionItemKeyValPair; |
| foreach (string optionItem in options) |
| { |
| optionItemoptionItemKeyValPair = optionItem.Split('$'); |
| radComboBox.Items.Add(new RadComboBoxItem(optionItemKeyValPair[0], optionItemKeyValPair[1])); |
| } |
| radComboBox.Items.Insert(0, new RadComboBoxItem(GetGlobalResourceObject("GeneralResource", "PleaseSelect").ToString(), "-1")); |
| if (!IsPostBack) radComboBox.FindItemByValue(property.DefaultValue).Selected = true; |
| templateControl.Controls.Add(radComboBox); |
| #endregion |
| break; |
| case "CheckBox": |
| #region |
| CheckBox checkBox = new CheckBox(); |
| checkBox.ID = string.Format("CheckBox_{0}", property.Id); |
| if (!IsPostBack) checkBox.Checked = property.DefaultValue == "0" ? false : true; |
| templateControl.Controls.Add(checkBox); |
| #endregion |
| break; |
| } |
| } |
and i call the method on grid's itemcreated event
| protected void SelectGrid_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| GridDataItem item = e.Item as GridDataItem; |
| Entities.Domain.Property property = item.DataItem as Entities.Domain.Property; |
| if (property != null && property.PropertyTypeCodelookup != null && !string.IsNullOrEmpty(property.PropertyTypeCodelookup.UiType)) |
| { |
| CreateCustomControl(item["PropertyValueColumn"], property); |
| } |
| } |
| } |
if i bind grid every page_load event of page,
when i want to take values that entered into this custom controls ,it does resets values.
and if i only bind grid once at pagepostback
when i want to take values over the controls it return null referance...
| public List<Property> SelectedProperties |
| { |
| get |
| { |
| List<Property> _selectedProperties=new List<Property>(); |
| Property tmpProperty; |
| if (_currentPropertyCollection != null && _currentPropertyCollection.Count > 0) |
| { |
| foreach (GridDataItem item in PropertySelectGrid.Items) |
| { |
| if (((CheckBox)item["Selection"].Controls[1]).Checked) |
| { |
| tmpProperty = _currentPropertyCollection.Find(p => p.Id == (Convert.ToInt64(item["Id"].Text))); |
| Control c = item["PropertyValueColumn"].Controls[0]; |
| string text = string.Empty; |
| if (c is RadTextBox || c is RadNumericTextBox) |
| { |
| if (c is RadTextBox) |
| { |
| text = ((RadTextBox)item["PropertyValueColumn"].Controls[0]).Text; |
| } |
| else if (c is RadNumericTextBox) |
| { |
| text = ((RadNumericTextBox)item["PropertyValueColumn"].Controls[0]).Text; |
| } |
| } |
| else if (c is RadDateInput) |
| { |
| if (((RadDateInput)item["PropertyValueColumn"].Controls[0]).SelectedDate.HasValue) |
| { |
| text = ((RadDateInput)item["PropertyValueColumn"].Controls[0]).SelectedDate.Value.ToString(); |
| } |
| } |
| else if (c is RadComboBox) |
| { |
| if (((RadComboBox)item["PropertyValueColumn"].Controls[0]).SelectedItem != null) |
| { |
| if (((RadComboBox)item["PropertyValueColumn"].Controls[0]).SelectedItem.Value != "-1") |
| { |
| text = ((RadComboBox)item["PropertyValueColumn"].Controls[0]).SelectedItem.Value; |
| } |
| } |
| } |
| else if (c is CheckBox) |
| { |
| if (((CheckBox)item["PropertyValueColumn"].Controls[0]).Checked) |
| { |
| text = "1"; |
| } |
| } |
| tmpProperty.DefaultValue = text; |
| _selectedProperties.Add(tmpProperty); |
| } |
| } |
| } |
| //string key = "UnitPropertySelectedList_" + WebSessionManager.DataFilter.CurrentId; |
| //if (!WebSessionManager.DataFilter.ObjectList.ContainsKey(key) || WebSessionManager.DataFilter.ObjectList[key] == null) |
| //{ |
| // List<Property> propertyList = new List<Property>(); |
| // WebSessionManager.DataFilter.Add(key, propertyList); |
| //} |
| //return (List<Property>)WebSessionManager.DataFilter.ObjectList[key]; |
| return _selectedProperties; |
| } |
and how can i bind controls on grid dynamically and got values entered to them ?