这一段代码出现"未将对象的引用应用到对象的实例?"的错误
希望高手指教!!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace case21
{
/// <summary>
/// index 的摘要说明。
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid show_person;
private string strConnectionString;
private SqlConnection conn;
private DataSet ds;
private SqlDataAdapter da;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
strConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
conn = new SqlConnection(strConnectionString);
conn.Open();
if(!IsPostBack)
{
DataGridBind();
}
}
public void DataGridBind()
{
string strsql="select user_id,username,sex,hometown,mobilephone,xueli,dep_name,zhiwu from user,dep where user.dep_id=dep.dep_id";
ds = new DataSet();
da =new SqlDataAdapter(strsql,conn);
da.Fill(ds,"User");
conn.Close();
DataView dv = ds.Tables[0].DefaultView;
show_person.DataSource = dv;
show_person.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.show_person.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.show_person_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void show_person_PageIndexChanged(object source,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.show_person.CurrentPageIndex = e.NewPageIndex;
DataGridBind();
}
}
}