取得控制項的值(TextBox、RadioButtonList、CheckBox、DropDownList、HiddenField)
取得控制項的值(TextBox、RadioButtonList、CheckBox、DropDownList、HiddenField)
public static string GetControlValue(Control ctl) {
if (ctl.GetType() == typeof(TextBox)) {
return ((TextBox)ctl).Text;
}
if (ctl.GetType() == typeof(RadioButtonList)) {
return ((RadioButtonList)ctl).SelectedValue;
}
if (ctl.GetType() == typeof(CheckBox)) {
return ((CheckBox)ctl).Text;
}
if (ctl.GetType() == typeof(DropDownList)) {
return ((DropDownList)ctl).SelectedValue;
}
if (ctl.GetType() == typeof(HiddenField)) {
return ((HiddenField)ctl).Value;
}
return "";
}