问题描述
为什么我的事件处理不起作用?我收到了这个错误。我正在运行VS 2008 / .NET 3.5 SP1 / Win XP,以防万一源代码可用。
错误1'InsertButton_Click'没有重载匹配委托'System.EventHandler'c:\inetpub \wwwroot \ Jon的Couch \ Articles.aspx.cs 21 31 http:// localhost / Jon's Couch /
Articles.aspx
How come my event handling is not working? I'm getting this error. I'm running VS 2008 / .NET 3.5 SP1 / Win XP, and, just in case the source code is available here.
Error1No overload for 'InsertButton_Click' matches delegate 'System.EventHandler'c:\inetpub\wwwroot\Jon's Couch\Articles.aspx.cs2131http://localhost/Jon's Couch/
Articles.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Articles.aspx.cs" Inherits="Articles" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>@Jon's</title>
</head>
<body>
<form id="form1" runat="server">
<h1>@Jon's <img src="images/sofa.jpg" alt="logo"/> </h1 >
<div style="float:left;width:122px">
<p style="width: 122px; height: 663px; margin-top: 0px; margin-right: 0px;">
<a href="About.aspx">About me</a> <br />
<a href="Diary.aspx">My diary</a> <br />
<a href="Articles.aspx">Articles</a> <br />
<a href="Bookmarks.aspx">My bookmarks</a> <br />
<a href="Promotions.aspx">Promotions</a> <br />
<a href="Resume.aspx">My resume</a> <br />
<a href="Warez.aspx">Filesharing</a> <br />
</p>
</div>
<div>
<asp:FormView ID="Envelope" runat="server" DataSourceID="SqlDataSource1"
AllowPaging="True">
<HeaderTemplate>
</HeaderTemplate>
<EditItemTemplate>
Timestamp:
<asp:TextBox ID="TimestampTextBox" runat="server"
Text='<%# Bind("Timestamp") %>' />
<br />
Subject:
<asp:TextBox ID="SubjectTextBox" runat="server" Text='<%# Bind("Subject") %>' />
<br />
EntryText:
<asp:TextBox ID="EntryTextTextBox" runat="server"
Text='<%# Bind("EntryText") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
<asp:Button ID="Edit" runat="server" Text="Edit" CommandName="edit" /> <br />
<asp:Button ID="New" runat="server" Text="New" CommandName="new" /> <br />
</EditItemTemplate>
<InsertItemTemplate>
Timestamp:
<asp:TextBox ID="TimestampTextBox" runat="server"
Text='<%# Bind("Timestamp") %>' />
<br />
Subject:
<asp:TextBox ID="SubjectTextBox" runat="server" Text='<%# Bind("Subject") %>' />
<br />
EntryText:
<asp:TextBox ID="EntryTextTextBox" runat="server"
Text='<%# Bind("EntryText") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" OnClick="InsertButton_Click" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Timestamp:
<asp:Label ID="TimestampLabel" runat="server" Text='<%# Bind("Timestamp") %>' />
<br />
Subject:
<asp:Label ID="SubjectLabel" runat="server" Text='<%# Bind("Subject") %>' />
<br />
EntryText:
<asp:Label ID="EntryTextLabel" runat="server" Text='<%# Bind("EntryText") %>' />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:couch_dbConnectionString %>"
SelectCommand="SELECT [Timestamp], [Subject], [EntryText] FROM [Article]"
UpdateCommand="UPDATE [Article] SET [Timestamp] = @Timestamp, [Subject] = @Subject, [EntryText] = @EntryText"
InsertCommand="INSERT INTO [Article] ([EntryID], [Timestamp], [Subject], [EntryText]) VALUES @EntryID, @Timestamp, @Subject, [EntryText]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
Articles.aspx.cs
Articles.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
public partial class Articles : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Title = "Jon's Couch";
}
protected delegate EventHandler InsertButton_Click (object sender, FormViewCommandEventArgs e);
InsertButton_Click += new System.EventHandler(this.InsertButton_Click);
protected void InsertButton_Click(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "new")
{
Envelope.DefaultMode = FormViewMode.Insert;
}
}
}
:confused:
:confused:
推荐答案
Articles.aspx.cs
Articles.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
public partial class Articles : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Title = "Jon's Couch";
}
protected delegate EventHandler InsertButton_Click (object sender, FormViewCommandEventArgs e);
InsertButton_Click += new System.EventHandler(this.InsertButton_Click);
protected void InsertButton_Click(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "new")
{
Envelope.DefaultMode = FormViewMode.Insert;
}
}
}
:confused:
:confused:
这篇关于'InsertButton_Click'没有重载匹配委托'System.EventHandler'[错误]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!