日期:2014-05-18 浏览次数:20442 次
public partial class Default4 : System.Web.UI.Page { private SqlConnection conn; private SqlCommand cmd; private SqlDataReader reader; protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) AddOnPreRenderCompleteAsync(new BeginEventHandler(BeginAsyncOperation), new EndEventHandler(EndAsyncOperation)); } IAsyncResult BeginAsyncOperation(object sender, EventArgs e, AsyncCallback cb, object state) { string str = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["GtKydjConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(str); cmd = new SqlCommand("select * from GtKydj", conn); conn.Open(); return cmd.BeginExecuteReader(cb, state); } void EndAsyncOperation(IAsyncResult ar) { reader = cmd.EndExecuteReader(ar); GridView1.DataSource = reader; GridView1.DataBind(); } public override void Dispose() { if (conn != null) conn.Close(); base.Dispose(); } }