首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

“DropDown1”: 成员名称不能与它们的封闭类型相同,该怎么解决

2012-03-07 
“DropDown1”: 成员名称不能与它们的封闭类型相同%@PageLanguage C# AutoEventWireup true CodeFile

“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)
        {
                string   SelectedText   =   DropDown1.SelectedItem.Text;


                string   SelectedValue   =   DropDown1.SelectedItem.Value;
                Label1.Text   =   "您选择的讨论区是: <font   color=red> "   +   SelectedText   +   " <br> </font> 值为: <font   color=red> "   +   SelectedValue   +   " </font> ";
        }
}


运行的时候,出现以下错误:

“DropDown1”:   成员名称不能与它们的封闭类型相同

[解决办法]
重新创建一个DropDownList,取名为 DropDownList1 试试
[解决办法]
把DropDownList的名称改下试试
[解决办法]
public partial class DropDown1 //你的类名也是这个,里面的成员就不能使DropDown1了

热点排行