“DropDown1”:
成员名称不能与它们的封闭类型相同<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "DropDownList1.aspx.cs " Inherits= "DropDown1 " %>
<!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> DropDownList 示例 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:DropDownList ID= "DropDown1 " runat= "server ">
</asp:DropDownList>
<asp:Button runat= "server " Text= "选择 " OnClick= "SubmitBtn_Click " />
<p>
<asp:Label ID= "Label1 " runat= "server " Text= " " Font-Size= "10pt "> 请选择一个讨论区 </asp:Label>
</p>
</div>
</form>
</body>
</html>
===========================================================================
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 DropDown1 : System.Web.UI.Page
{
protected void Page_Load(object src, EventArgs e)
{
DropDown1.Items.Add(new ListItem( "ASP.NET区 ", "ASP.NET "));
DropDown1.Items.Add(new ListItem( "JSP区 ", "JSP "));
DropDown1.Items.Add(new ListItem( "C#区 ", "C# "));
DropDown1.Items.Add(new ListItem( "PHP区 ", "PHP "));
DropDown1.Items.Add(new ListItem( "VBVC区 ", "VBVC "));
DropDown1.Items.Add(new ListItem( "HTML区 ", "HTML "));
}
void SubmitBtn_Click(object sender, EventArgs e)