0
콤보 상자, 확인란 또는 텍스트 상자에서 선택한 값을 반환하려는 클래스를 만들었습니다.ASP.NET WebForms에서 FindControl을 사용하여 알 수없는 형식의 값을 반환하는 중
코드는 다음과 같습니다
private string GetControlValue(string controlId)
{
var control = FindControl(controlId);
if (control.GetType() == typeof(RadTextBox))
{
return ((RadInputControl)control).Text;
}
else if (control.GetType() == typeof(RadComboBox))
{
return ((RadComboBox)control).SelectedValue;
}
else if (control.GetType() == typeof(CheckBox))
{
return ((CheckBox)control).Checked.ToString();
}
else
{
return null;
}
}
내가 좀 더 효율적인 방법으로이 작업을 수행 할 수 있습니까? 내 예제는 권투 각 유형있을 수 있으며 성능을 끌어냅니다 같아요.
private string GetControlValue(string controlId)
{
var control = FindControl(controlId);
var radTextBox = control as RadTextBox;
if (radTextBox != null)
{
return radTextBox.Text;
}
var radComboBox = control as RadComboBox;
if (radComboBox != null)
{
return radComboBox.SelectedValue;
}
var checkBox = control as CheckBox;
if (checkBox != null)
{
return checkBox.Checked.ToString();
}
return null;
}
가 BTW : 권투 코드에서 발생되지
감사합니다. 나는 누군가에게 또 다른 제안이있는 경우 잠시 동안 이것을 공개하지 않는다. –