Atlas ASP.Net C# Listbox动态添加数据响应问题
.cs
======
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ListBox1.Items.Clear();
ListBox1.Items.Add("n1");
ListBox1.Items.Add("n2");
ListBox1.Items.Add("n3");
ListBox1.SelectedIndexChanged += new EventHandler(ListBox1_SelectedIndexChanged);
}
void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
ListBox ls = (ListBox)sender;
Label1.Text = ls.Items[ls.SelectedIndex].Value;
}
}
===========
.aspx
==========
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" Height="155px" Width="71px">
</asp:ListBox>
<asp:Label ID="Label1" runat="server" Text="Label" Width="100px"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
===============
报错超出索引。