如何在C#aspnet中检查是否存在下拉列表



如何检查页面上是否存在下拉列表?当页面上找不到下载列表时,我想验证某个条件。如果找不到任何下拉列表,它将不会运行代码string test = DropDownList1.SelectedItem.Text.ToString();

我尝试过的:

if (DropDownList1 not exist) 
{ 
//
}
string test = DropDownList1.SelectedItem.Text.ToString();
if (DropDownList1 != null) 
{ 
string test = DropDownList1.SelectedItem.Text.ToString();
}

或者:

if (DropDownList1 == null) 
{ 
//Do stuff
return;
}
string test = DropDownList1.SelectedItem.Text.ToString();

最新更新