请各位仁兄帮我看看我的代码哪有问题.编译器能够通过,但是在web上运行时,显示"编译器错误信息: CS0117: “ASP.webform1_aspx”并不包含“DataGrid_Edit”的定义"
具体web显示请见附件
前台代码:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="artical.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id="dg" style="Z-INDEX: 101; LEFT: 203px; POSITION: absolute; TOP: 212px" runat="server" Width="400px" Height="167px" OnEditCommand="DataGrid_Edit" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" OnDeleteCommand="DataGrid_Delete" DataKeyField="AbstractID" AutoGenerateColumns="False" MaintainState="false">
<Columns>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="更新" CancelText="取消" EditText="编辑">
<ItemStyle Wrap="False"></ItemStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" CommandName="Delete">
<ItemStyle Wrap="False"></ItemStyle>
</asp:ButtonColumn>
<asp:BoundColumn DataField="AbstractID" ReadOnly="True" HeaderText="abstractid"></asp:BoundColumn>
<asp:BoundColumn DataField="AbstractTitle" HeaderText="abstracttitle"></asp:BoundColumn>
</Columns>
</asp:DataGrid></FONT> <span id="Message" MaintainState="false" runat="server"></span>
</form>
</body>
</HTML>
后台代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace artical
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dg;
protected System.Web.UI.HtmlControls.HtmlGenericControl Message;
OleDbConnection Conn;
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
String Provider,DataBase,ConnStr,SQL;
Provider = "Microsoft.Jet.OLEDB.4.0;";
DataBase = Server.MapPath("icccbe_xii_designed_by_zyl.mdb");
ConnStr = "Provider="+Provider+"Data Source="+DataBase;
Conn = new OleDbConnection(ConnStr);
if (!IsPostBack) BindGrid();
}
#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.dg.SelectedIndexChanged += new System.EventHandler(this.dg_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
void DataGrid_Edit(Object sender,DataGridCommandEventArgs E)
{
dg.EditItemIndex = (int)E.Item.ItemIndex;
BindGrid();
}
void DataGrid_Cancel(Object sender,DataGridCommandEventArgs E)
{
dg.EditItemIndex = -1;
BindGrid();
}
void DataGrid_Update(Object sender,DataGridCommandEventArgs E)
{
String strSQL = "UPDATE grade SET "+"AbstractTitle='"+((TextBox)E.Item.Cells[3].Controls[0]).Text+"' where AbstractID="+dg.DataKeys[(int)E.Item.ItemIndex];
OleDbCommand cm = new OleDbCommand(strSQL,Conn);
Conn.Open();
try
{
cm.ExecuteNonQuery();
Message.InnerHtml="<b>编辑成功</b>";
// 退出编辑状态
dg.EditItemIndex=-1;
}
catch (OleDbException)
{
Message.InnerHtml="编辑失败";
Message.Style["color"]="red";
}
cm.Connection.Close();
// 更新DataGrid
BindGrid();
}
// 处理删除事件
public void DataGrid_Delete(Object sender,DataGridCommandEventArgs E)
{
String strSQL="DELETE FROM grade WHERE AbstractID="
+ dg.DataKeys[(int)E.Item.ItemIndex];
OleDbCommand cm = new OleDbCommand(strSQL,Conn);
Conn.Open();
try
{
cm.ExecuteNonQuery();
Message.InnerHtml = "<b>删除成功</b>";
}
catch (OleDbException)
{
Message.InnerHtml = "<b>删除失败</b>";
Message.Style["color"]="red";
}
Conn.Close();
BindGrid();
}
public void BindGrid()
{
OleDbDataAdapter da=new OleDbDataAdapter("select * from grade",Conn);
DataSet ds = new DataSet();
da.Fill(ds);
dg.DataSource=ds;
dg.DataBind();
}
private void dg_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}