求助 ,网站源码运行没问题,发布就出错

woxingtianxia123 2011-11-06 06:26:05
网站源码运行没问题,发布就出错

错误 2 “System.Web.UI.WebControls.TextBox”并不包含“Items”的定义 create.cs 50

.aspx 中有这样一个控件

<asp:DropDownList ID="xType" runat="server" Width="120px">
<asp:ListItem Value="0">请选择</asp:ListItem>
</asp:DropDownList>

相应的.cs 中有一个这样的代码

DataTable dt = this.GetTypeList();

for( int i = 0;i<dt.Rows.Count;i++)
{
ListItem item = new ListItem();

item.Text = dt.Rows[i]["TypeName"].ToString();
item.Value = dt.Rows[i]["TypeName"].ToString();

this.xType.Items.Add(item);
}


错误出现在 this.xType.Items.Add(item);


错误 2 “System.Web.UI.WebControls.TextBox”并不包含“Items”的定义 create.cs 50


求助 ,怎么解决这个问题 。
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
woxingtianxia123 2011-11-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 taomanman 的回复:]
你的代码怎么写的那么别扭,像下面这样不是很简洁嘛??


C# code

<asp:DropDownList ID="xType" runat="server" Width="120px">
</asp:DropDownList>


DataTable dt = this.GetTypeList();
this.xType.DataSource = dt;
this.xT……

[/Quote]

呵呵,谢谢你,我水平有限。
WJY_123456 2011-11-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 nianhui 的回复:]
是不是有一个TextBox也叫xType?
[/Quote]
有可能,是不是有个页面也有同名的控件
#blackheart 2011-11-06
  • 打赏
  • 举报
回复
是不是有一个TextBox也叫xType?
暖枫无敌 2011-11-06
  • 打赏
  • 举报
回复
你的代码怎么写的那么别扭,像下面这样不是很简洁嘛??


<asp:DropDownList ID="xType" runat="server" Width="120px">
</asp:DropDownList>


DataTable dt = this.GetTypeList();
this.xType.DataSource = dt;
this.xType.DataTextField = "TypeName";
this.xType.DataValueField = "TypeName";
this.xType.DataBind();
this.xType.Items.Insert(0,"请选择");

黄亮 2011-11-06
  • 打赏
  • 举报
回复
站点模式还是Project的项目?我一般用Project的。
站点模式App_Code目录下的CS也要发布出去。看看是不是漏了。

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧