高分请教
Truly 2003-08-19 09:48:41 我在vs.net环境中编辑如下代码后
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "作者");
MyDataGrid.DataSource=ds.Tables["作者"].DefaultView;
MyDataGrid.DataBind();
}
服务器自动添加了一些代码:
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.MyDataGrid.SelectedIndexChanged += new System.EventHandler(this.MyDataGrid_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
而一编译就提示出错,说什么MyDataGrid.SelectedIndexChanged未定义,我将
this.MyDataGrid.SelectedIndexChanged += new System.EventHandler(this.MyDataGrid_SelectedIndexChanged);
代码行删除后可以正常编译和显示了。
请问vs.net自动添加的那段代码什么意思?有何作用?
我删除的那段代码又有何作用?
请高手指点。谢谢。