编译器错误信息: CS0123: “MyList_Page”的重载均与委托“System.EventHandler”不匹配

以前遇到过几次类似 “XXXXX” 的重载均与委托“XXXXXX”不匹配  这样的错误,都没有得到解决,一头雾水,今天在几个朋友的帮助下终于解决了这个问题,这类问题出现的原因就是在控件的一些事件里面调用了函数,而这些函数的参数与该事件所要用到的参数类型不一致。比如:

<asp:GridView ID="MyList" AllowPaging="true" PageSize="10" OnPageIndexChanged="MyList_Page" runat="server" Width="500" GridLines="None" CellPadding="2" CellSpacing="1" Font-Size="8pt" Font-Names="宋体" AutoGenerateColumns="false" EnableViewState="false" DataKeyNames="id" OnRowDeleted="MyDataGrid_Delete">
                        <Columns>
                          <asp:ButtonField ItemStyle-Width="150px" HeaderText="" DataTextField="shijian" />
                          <asp:HyperLinkField ItemStyle-Width="400px" HeaderText="" DataNavigateUrlFields="id" DataNavigateUrlFormatString="update.aspx?id={0}" DataTextField="biaoti" Target="_blank" />
                          <asp:ButtonField ItemStyle-Width="100px" Text="删除" CommandName="Delete" />
                        </Columns>
                        </asp:GridView>

*******************************************************************************************************************************************
        public void MyList_Page(object sender, GridViewPageEventArgs e)
        {
            MyList.PageIndex= e.NewPageIndex;
            DataBind();
        }

*****************************************************************************************************************************

运行时候有错误:

编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误信息: CS0123: “MyList_Page”的重载均与委托“System.EventHandler”不匹配

源错误:

 

行 25:                 <td style="width:608;">
行 26:                     <div style="text-align: center">
行 27:                         <asp:GridView ID="MyList" AllowPaging="true" PageSize="10" OnPageIndexChanged="MyList_Page" runat="server" Width="500" GridLines="None" CellPadding="2" CellSpacing="1" Font-Size="8pt" Font-Names="宋体" AutoGenerateColumns="false" EnableViewState="false" DataKeyNames="id" OnRowDeleted="MyDataGrid_Delete">
行 28:                         <Columns>
行 29:                           <asp:ButtonField ItemStyle-Width="150px" HeaderText="" DataTextField="shijian" />
 

源文件: h:/ASP.NET/WebSites/WebSite2/xinwen/update.aspx    行: 27

这个就是典型的出错例子,在MSDN中搜索OnPageIndexChanging、OnPageIndexChanged等关键字就可以得到:

C#
protected virtual void OnPageIndexChanged (
 EventArgs e
)

C#
protected virtual void OnPageIndexChanging (
 DetailsViewPageEventArgs e
)

C#
protected virtual void OnRowDeleting (
 GridViewDeleteEventArgs e
)

C#
protected virtual void OnRowDeleted (
	DataRowChangeEventArgs e
)

这样,在何种事件中使用什么样的参数类型就一目了然了。还有后面的OnRowDeleted、OnRowDeleting也是同样的道理。于是,可以将GridView控件改成以下:

                        <asp:GridView ID="MyList" AllowPaging="true" PageSize="10" OnPageIndexChanging="MyList_Page" runat="server" Width="590px"
                        GridLines="None" CellPadding="2" CellSpacing="1" Font-Size="10pt" Font-Names="宋体" AutoGenerateColumns="false"
                        EnableViewState="false" DataKeyNames="id" OnRowDeleting="MyDataGrid_Delete" >
                        <Columns>
                          <asp:ButtonField DataTextField="shijian" >
                              <ItemStyle Width="150px" />
                          </asp:ButtonField>
                          <asp:HyperLinkField DataNavigateUrlFields="id"
                          DataNavigateUrlFormatString="update.aspx?id={0}" DataTextField="biaoti" Target="_blank" >
                              <ItemStyle Width="400px" />
                          </asp:HyperLinkField>
                          <asp:ButtonField Text="删除" CommandName="Delete" >
                              <ItemStyle Width="100px" />
                          </asp:ButtonField>
                        </Columns>
                        </asp:GridView>


相应事件:

public void MyList_Page(object sender, GridViewPageEventArgs e)
public void MyDataGrid_Delete(Object sender, GridViewDeleteEventArgs e)

你可能感兴趣的:(object,server,C#,delete,asp,编译器)