方法与委托不匹配
CS0123: 方法“Web.ProdListByType.IndexChanging(object, System.EventArgs)”与委托“void System.Web.UI.WebControls.CommandEventHandler(object, System.Web.UI.WebControls.CommandEventArgs)”不匹配以下是代码
<asp:DataList ID=”dlData” runat=”server” RepeatColumns=”4″ >
<ItemTemplate>
<asp:Label ID=”lblName” runat=”server” /><br />
<asp:Label ID=”lblTime” runat=”server” />
</ItemTemplate>
</asp:DataList>
<asp:linkbutton ID=”lkPre” OnCommand=”IndexChanging” CommandArgument=”pre” runat=”server” >PREVIOUS PAGE></asp:linkbutton>
<asp:linkbutton ID=”lkNext” OnCommand=”IndexChanging” CommandArgument=”next” runat=”server” >NEXT PAGE</asp:linkbutton>
protected void IndexChanging(object sender,EventArgs e)
{
string strCommand = ((LinkButton)sender).CommandArgument.ToString();
int pageindex = int.Parse(ViewState["pageindex"].ToString());
if(strCommand == "pre")
{
pageindex = pageindex - 1;
}
else
{
pageindex = pageindex + 1;
}
ViewState["pageindex"] = pageindex;
BindProdList();
}
--------------------编程问答-------------------- CommandEventHandler的第二个参数是CommandEventArgs类型,你的IndexChanging第二个参数是EventArgs;显然不匹配了 --------------------编程问答-------------------- 这个你改一下代码就可以了,就是把EventArgs 改成LinkButton事件的CommandEventArgs :
--------------------编程问答-------------------- CommandArgument的值是固定的,,方法也是固定的,,你重写的方式不对 --------------------编程问答-------------------- 同意楼上 --------------------编程问答-------------------- 委托参数必须与方法参数类型一致 --------------------编程问答-------------------- 委托的参数类型,必须和方法的参数类型一致 --------------------编程问答-------------------- 同3楼
protected void IndexChanging(object sender, CommandEventArgs e)
{
string strCommand = ((LinkButton)sender).CommandArgument.ToString();
int pageindex = int.Parse(ViewState["pageindex"].ToString());
if (strCommand == "pre")
{
pageindex = pageindex - 1;
}
else
{
pageindex = pageindex + 1;
}
ViewState["pageindex"] = pageindex;
BindProdList();
}
补充:.NET技术 , ASP.NET