日期:2014-05-17  浏览次数:20456 次

关于response的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
  public string str = @"Data Source=.\SQLEXPRESS;AttachDbFilename=""d:\Visual Studio 2010\WebSites\WebSite2\App_Data\Database.mdf"";Integrated Security=True;User Instance=True";
  protected void Page_Load(object sender, EventArgs e)
  {
  Response.Write("haha");
  }
 
  protected void Button1_Click1(object sender, EventArgs e)
  {
  Response.Write("haha2");
  Date d1 = new Date();
  d1.ReadOrderData(str);
  }
}
class Date 
{
  public void ReadOrderData(string connectionString)
  {
  string queryString =
  "SELECT name, passwd FROM Date1;";
  using (SqlConnection connection =
  new SqlConnection(connectionString))
  {
  SqlCommand command =
  new SqlCommand(queryString, connection);
  connection.Open();

  SqlDataReader reader = command.ExecuteReader();

  // Call Read before accessing data.
  while (reader.Read())
  {
  Response.Write(String.Format("{0}, {1}",
  reader[0], reader[1]));
  }

  // Call Close when done reading.
  reader.Close();
  }
  }

}
Date类中的最后那个response.write();显示上下文不存在response,我该如何让这方法输出到页面呢?

------解决方案--------------------
让类 集成 
class Date : System.Web.UI.Page
------解决方案--------------------
System.Web.HttpContext.Current.Response.w.......