菜鸟菜问题: 结果显示的问题
我参考下面这段代码 在第24 行 HtmlContent.Text = htmlStr.ToString();
提示 “当前上下文中不存在名称“HtmlContent” ”
我用textbox代替, 显示结果 ,一行到头,
我新建一个HTML页, 名字就叫HtmlContent ,没用。
请教该怎么做。
01 public partial class _Default : System.Web.UI.Page
02 {
03 protected void Page_Load(object sender, EventArgs e)
04 {
05 string connectionString =
06 ConfigurationManager.ConnectionStrings[ "Northwind "].ConnectionString;
07 SqlConnection con = new SqlConnection(connectionString);
08 string sql = "SELECT top 5 CustomerID,CompanyName,ContactName,Address
09 FROM Customers ";
10 SqlCommand cmd = new SqlCommand(sql, con);
11 con.Open();
12 SqlDataReader reader = cmd.ExecuteReader();
13 StringBuilder htmlStr = new StringBuilder( " ");
14 while (reader.Read())
15 {
16 htmlStr.Append( "CustomerID: " + reader[ "CustomerID "] + " <br> ");
17 htmlStr.Append( "CompanyName: " + reader[ "CompanyName "] + " <br> ");
18 htmlStr.Append( "ContactName: " + reader.GetString(2) + " <br> ");
19 htmlStr.Append( "Address: " + reader.GetString(3) + " <br> ");
20 htmlStr.Append( " <hr> ");
21 }
22 reader.Close();
23 con.Close();
24 HtmlContent.Text = htmlStr.ToString();
25 }
26 }
------解决方案--------------------HtmlContent在类或者ash文件中用到,不是很熟悉.
不过你上面的代码,为什么不直接response.write?
------解决方案--------------------Response.Write
大小写