输入字符串在ASP.NET中的格式不正确

本文关键字:格式 不正确 NET 字符串 ASP 输入 | 更新日期: 2023-09-27 18:22:06

每次运行以下代码时,它都会不断地说"输入字符串的格式不正确"。我尝试了两种不同的方法,但仍然失败了。如何解决此问题?

protected void CEButton_Click(object sender, EventArgs e)
{
    Session["CE"] = CEDropDownList.Text;
}

输入字符串在ASP.NET中的格式不正确

如果CEDropDownList是Dropdown控件类型,您将查找CEDropDownList.SelectedItem.Text

假设你的下拉列表如下:

<asp:DropDownList ID="CEDropDownList" runat="server">
      <asp:ListItem Value="foo">Bar</asp:ListItem>
</asp:DropDownList>

要获得foo,您需要使用CEDropDownList.SelectedItem.Text

要获得Bar,您需要使用CEDropDownList.SelectedItem.Value