Code Bye

事件的重载与委托“System.EventHandler”不匹配

 

错误提示:【编译器错误消息: CS0123: “GridView1_RowCommand”的重载均与委托“System.EventHandler”不匹配】
代码如下:
C#:
pre class=”brush: csharp”>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default5 : System.Web.UI.Page
{
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == “information”)
        {
            Label1.Text = “姓名=” + e.CommandArgument.ToString();
        }
    }
}
JS:
pre class=”brush: javascript”><!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/>
    <title></title>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
    
        <asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>
    
    </div>
        <asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”  DataSourceID=”SqlDataSource1″ OnSelectedIndexChanged=”GridView1_RowCommand”>
            <Columns>
                <asp:BoundField DataField=”部门” HeaderText=”部门” SortExpression=”部门” />
                <asp:BoundField DataField=”省区” HeaderText=”省区” SortExpression=”省区” />
                <asp:BoundField DataField=”办事处” HeaderText=”办事处” SortExpression=”办事处” />
                <asp:BoundField DataField=”职级” HeaderText=”职级” SortExpression=”职级” />
                <asp:BoundField DataField=”办公电话” HeaderText=”办公电话” SortExpression=”办公电话” />
                <asp:BoundField DataField=”姓名” HeaderText=”姓名” SortExpression=”姓名” />
                <asp:BoundField DataField=”备注电话” HeaderText=”备注电话” SortExpression=”备注电话” />
                <asp:BoundField DataField=”电子邮箱” HeaderText=”电子邮箱” SortExpression=”电子邮箱” />
                <asp:BoundField DataField=”备注” HeaderText=”备注” SortExpression=”备注” />
                <asp:ButtonField ButtonType=”Button” Text=”按钮” CommandName=”informatiom”/>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\VB制作\通讯录best2\数据库\dahaoda-txl.mdb” ProviderName=”System.Data.OleDb” SelectCommand=”SELECT [部门], [省区], [办事处], [职级], [办公电话], [姓名], [备注电话], [电子邮箱], [备注] FROM [XXXX]”></asp:SqlDataSource>
    </form>
</body>
</html>

 

40分
你好,GridView1_RowCommand方法的事件是onrowdatabound,而非OnSelectedIndexChanged
更正是:onrowcommand事件
不匹配 参数类型不对
事件里面第二个事件类型写错了
错误的原因:
OnSelectedIndexChanged的委托是System.EventHandler(Object sender, EventArgs e),所以应该用onRowCommand
更改如下:
<!DOCTYPE html>
 
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/>
    <title></title>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
     
        <asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>
     
    </div>
        <asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”  DataSourceID=”SqlDataSource1″ OnRowCommand=”GridView1_RowCommand”>
            <Columns>
                <asp:BoundField DataField=”部门” HeaderText=”部门” SortExpression=”部门” />
                <asp:BoundField DataField=”省区” HeaderText=”省区” SortExpression=”省区” />
                <asp:BoundField DataField=”办事处” HeaderText=”办事处” SortExpression=”办事处” />
                <asp:BoundField DataField=”职级” HeaderText=”职级” SortExpression=”职级” />
                <asp:BoundField DataField=”办公电话” HeaderText=”办公电话” SortExpression=”办公电话” />
                <asp:BoundField DataField=”姓名” HeaderText=”姓名” SortExpression=”姓名” />
                <asp:BoundField DataField=”备注电话” HeaderText=”备注电话” SortExpression=”备注电话” />
                <asp:BoundField DataField=”电子邮箱” HeaderText=”电子邮箱” SortExpression=”电子邮箱” />
                <asp:BoundField DataField=”备注” HeaderText=”备注” SortExpression=”备注” />
                <asp:ButtonField ButtonType=”Button” Text=”按钮” CommandName=”informatiom”/>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\VB制作\通讯录best2\数据库\dahaoda-txl.mdb” ProviderName=”System.Data.OleDb” SelectCommand=”SELECT [部门], [省区], [办事处], [职级], [办公电话], [姓名], [备注电话], [电子邮箱], [备注] FROM [XXXX]”></asp:SqlDataSource>
    </form>
</body>
</html>

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明事件的重载与委托“System.EventHandler”不匹配