public bool SetFindControlValue(string ctlID, HiddenField hfBase, string value, bool?enabled) { bool success = false; try { string ctlType = ctlID.Substring(0, 2); switch (ctlType) { case "cb": CheckBox cb = (CheckBox)hfBase.FindControl(ctlID); cb.Checked = Convert.ToBoolean(value); if (enabled != null) { cb.Enabled = (bool)enabled; } success = true; break; case "dd": DropDownList ddl = (DropDownList)hfBase.FindControl(ctlID); ddl.SelectedValue = value; if (enabled != null) { ddl.Enabled = (bool)enabled; } success = true; break; case "hf": HiddenField hf = (HiddenField)hfBase.FindControl(ctlID); hf.Value = value; success = true; break; case "lb": Label lbl = (Label)hfBase.FindControl(ctlID); lbl.Text = value; success = true; break; case "rb": RadioButtonList rb = (RadioButtonList)hfBase.FindControl(ctlID); rb.SelectedValue = value; if (enabled != null) { rb.Enabled = (bool)enabled; foreach (ListItem item in rb.Items) { item.Enabled = (bool)enabled; } } success = true; break; case "tb": TextBox tb = (TextBox)hfBase.FindControl(ctlID); tb.Text = value; if (enabled != null) { tb.Enabled = (bool)enabled; } success = true; break; case "lx": // set single selection ListBox lbx = (ListBox)hfBase.FindControl(ctlID); foreach (ListItem item in lbx.Items) { item.Selected = false; if (value == item.Value) { item.Selected = true; } } break; default: break; } } catch { } return(success); }
public string GetFindControlValue(string ctlID, HiddenField hfBase, out bool success) { success = false; string value = ""; try { string ctlType = ctlID.Substring(0, 2); switch (ctlType) { case "cb": CheckBox cb = (CheckBox)hfBase.FindControl(ctlID); value = cb.Checked.ToString(); success = true; break; case "dd": DropDownList ddl = (DropDownList)hfBase.FindControl(ctlID); if (ddl.SelectedIndex >= 0) { value = ddl.SelectedValue; success = true; } break; case "hf": HiddenField hf = (HiddenField)hfBase.FindControl(ctlID); value = hf.Value; success = true; break; case "lb": Label lbl = (Label)hfBase.FindControl(ctlID); value = lbl.Text; success = true; break; case "rb": RadioButtonList rb = (RadioButtonList)hfBase.FindControl(ctlID); value = rb.SelectedValue; success = true; break; case "tb": TextBox tb = (TextBox)hfBase.FindControl(ctlID); value = tb.Text; success = true; break; case "lx": // get single selected item ListBox lbx = (ListBox)hfBase.FindControl(ctlID); value = lbx.SelectedValue; success = true; break; default: break; } } catch { } return(value); }