当我将 AutoPostback = True 添加到我的 DropDownList (使用 OnSelectedIndexChanged)时,我得到一个 System.ArgumentNullException: Value cannot be null。
我的控件如下所示:
<asp:DropDownList ID="dropdown" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdown_OnSelectedIndexChanged" />
以及填充控件的代码:
dropdown.Items.Add(new ListItem("Item 1", "1"));
dropdown.Items.Add(new ListItem("Item 2", "2"));
dropdown.Items.Add(new ListItem("Item 3", "3"));
更新
在使用以下代码添加空页面时,我也收到错误消息:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_dev_test_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server" />
</div>
</form>
</body>
</html>