这段代码哪有问题,是不是控件定义的不对?
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;
using System.Data.SqlClient;
public partial class Module_CommonPage : System.Web.UI.Page
{
SqlCon SqlConnX = new SqlCon();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//绑定户型
SqlConnection MySql = SqlConnX.getCon();
MySql.Open();
SqlCommand SqlCmd = new SqlCommand("select * from HomeType", MySql);
SqlDataReader Sdr = SqlCmd.ExecuteReader();
this.DropDownList1.DataSource = Sdr;
this.DropDownList1.DataTextField = "HomeModel";
this.DropDownList1.DataBind();
Sdr.Close();
MySql.Close();
}
}
}
一运行就报错
“Module_CommonPage”并不包含“DropDownList1”的定义 F:\Ex02_02\CommonPage.aspx.cs 25 18 F:\Ex02_02\
” --------------------编程问答-------------------- .aspx页面的code亮出来seesee --------------------编程问答-------------------- 查找代码中是否有 DropDownList1
查看页面aspx中是否有ID="DropDownList1"的控件
--------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CommonPage.aspx.cs" Inherits="Module_CommonPage" %>
<!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 style="text-align: center; background-image: url(./Images/SysSkin/right.jpg);">
<form id="form1" runat="server">
<div style="text-align: left">
<br />
<br />
<br />
<br />
<table style="width: 613px">
<tr>
<td style="width: 133px; height: 24px;">
<asp:Label ID="Label1" runat="server" Text="户 型:" Width="53px" Font-Size="12pt" style="font-size: 12pt"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" Width="73px" AutoPostBack="True">
</asp:DropDownList></td>
<td style="width: 133px; height: 24px;">
<asp:Label ID="Label2" runat="server" Font-Size="12pt" Style="font-size: 12pt" Text="面 积:"
Width="52px"></asp:Label> <asp:DropDownList ID="DropDownList2" runat="server"
Width="73px">
</asp:DropDownList></td>
<td style="height: 24px">
</td>
</tr>
<tr>
<td style="width: 133px; height: 21px;">
</td>
<td style="height: 21px; width: 133px;">
</td>
<td style="height: 21px">
</td>
</tr>
<tr>
<td style="width: 133px">
</td>
<td style="width: 133px">
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
--------------------编程问答-------------------- ms没有问题,换个id也不行吗? --------------------编程问答-------------------- 在这一页上放什么控件都不行,还怪了 --------------------编程问答-------------------- -_-!!!
我把你的代码拷下来,前几秒中后台不能显示前台的控件id。
过一会就正常了。没报错~~~ --------------------编程问答-------------------- 你把页面删除了再从新建一个命名为一样的就可以然后再从新编译一下就可以了! --------------------编程问答-------------------- 谢谢!我从建了一个就好了 --------------------编程问答-------------------- up
补充:.NET技术 , ASP.NET