我有一个组合框,我在页面加载方法中添加了项目,在按钮单击中,我试图设置键入的文本或从下拉列表中选择的项目。我正在使用ComboBox.SelectedItem.ToString(),当输入内容时可以正常工作,但是一旦用户从下拉列表中选择了某些内容,字符串为空即可通过。
protected void Page_Load(object sender, EventArgs e)
{
if (ScriptManager.GetCurrent(Page) == null)
{
Page.Form.Controls.AddAt(0, new ScriptManager());
}
DiffComboBoxUrls.Items.Add(XMLConstants.PolicyStoreApplications.Value1);
DiffComboBoxUrls.Items.Add(XMLConstants.PolicyStoreApplications.Value2);
DiffComboBoxUrls.Items.Add(XMLConstants.PolicyStoreApplications.Value3);
DiffComboBoxUrls.Items.Add(XMLConstants.PolicyStoreApplications.Value4);
DiffComboBoxUrls.Items.Add(XMLConstants.PolicyStoreApplications.Value5);
}
protected void ChangeAppSettings_Click(object sender, EventArgs e)
{
string FOPath = FODirectory.Text;
string PolicyStoreName = DiffComboBoxUrls.SelectedItem.ToString(); //this comes back as "" when an item is selected and works when something is typed in
.....
}