现像描述:

 

编译器错误信息: CS0117: “ASP.upload_aspx”并不包含“DataList1_DeleteCommand”的定义

源错误:

行 47: 		<form id="Form1" method="post" runat="server">
            行 48:             <div class="tb_title"> 案号:<%=ajbh%></div><br>
            行 49: 			<asp:DataList ID="DataList1" Runat="server" DataKeyField="pic_id" RepeatDirection="Horizontal"
            行 50: 				RepeatColumns="8" Font-Size="X-Small" CellSpacing="1" BorderWidth="1px" CellPadding="1" BorderStyle="Dashed"
            行 51: 				GridLines="Both" OnDeleteCommand="DataList1_DeleteCommand">

 

 

原因: vs.net 2003事件是在.cs里用代码加上去的,迁移后vs.net 2005后,代码没有相应的自动改过来。

 

/// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.DataList1.DeleteCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_DeleteCommand);
   this.DataList1.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.DataList1_ItemDataBound);

  }
  #endregion

 

private void DataList1_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)

 

更新到vs.net 2005后,事件是写在aspx里的,对于丢失的事件

1.可以删掉vs.net 2003时代自动生成的那一整段。

 

#region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.DataList1.DeleteCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_DeleteCommand);
   this.DataList1.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.DataList1_ItemDataBound);

  }
  #endregion

 

 

2.在IDE中或是aspx中确定事件指定过了。

3.在cs中把private 改成protected或是public

protected void DataList1_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
  *因为只有public 和protected的可以在Aspx里使用。

  

posted on 2008-07-24 00:06  使名扬  阅读(1080)  评论(2编辑  收藏  举报