'lnkCustomer_Click'的重载不匹配委托'System.EventHandler' [英] No overload for 'lnkCustomer_Click' matches delegate 'System.EventHandler'

查看:289
本文介绍了'lnkCustomer_Click'的重载不匹配委托'System.EventHandler'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要使用以下代码将gridview列中的Text设置为不同于gridview中显示的内容:

need to set the Text in a gridview column to something other than what shows up in gridview with this code:

<asp:LinkButton ID="lnkCustomer" runat="server"

     OnClick="lnkCustomer_Click" Text='<%# Eval("ImgLnk") %>'></asp:LinkButton>


当然,显示的是字符串形式的"ImgLnk"的内容,这是一个超链接,即"http://...."我宁愿在gridview中说"Picture".

我正在尝试使用此组合:

默认aspx:


Of course what shows up is the contents of "ImgLnk" in string form which is a hyper link ie "http://...." I would rather it say "Picture" in gridview.

I am trying to use this combo:

Default aspx:

<asp:TemplateField HeaderText="StoreImg">
                        <ItemTemplate><asp:LinkButton ID="LinkButton1" runat="server"

                        OnClick="lnkCustomer_Click" Text='Picture'

                            CommandName="CustomerLink" CommandArgument='<%# Eval("ImgLnk") %>'></asp:LinkButton>


背后的代码:


Code behind:

protected void lnkCustomer_Click(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "CustomerLink")
        {
            Response.Redirect(e.CommandArgument.ToString());

       }


我收到此错误消息:


I get this error message:

No overload for 'lnkCustomer_Click' matches delegate 'System.EventHandler'	Default.aspx		


我已经尝试了很多,但是似乎无法纠正.请帮忙.

谢谢!


I have tried and tried, but I can''t seem to make the correction. Please help.

Thanks!

推荐答案

正如Wes在他的评论中指出的那样,您的方法定义不正确.
如果您在这种情况下正在响应LinkBut​​ton上的click事件,则该方法必须具有与protected void MethodName(object sender, EventArgs e)匹配的定义.您正在使用GridViewCommandEventArgs,该函数用于响应来自DataGrid的Command事件.

更新:如果从GridView中使用LinkBut​​ton,则您不想将onclick处理程序设置作为LinkBut​​ton html元素的一部分,而是希望在网格本身的oncommand处理程序中使用,在这种情况下,您的原始代码
As Wes has pointed out in his comment, the definition of your method is incorrect.
If you are responding to a click event on a LinkButton as you are in this case, then the method must have a definition that matches protected void MethodName(object sender, EventArgs e). Yours is using GridViewCommandEventArgs which is used to respond to Command events from a DataGrid.

Update: If the LinkButton is used from within the GridView, then you won''t want to have the onclick handler setup as part of the LinkButton html element, but rather in the oncommand handler for the grid itself, in which case your original code will work as is.


System.EventHandler委托希望您有一个带有特定签名的方法.请参阅: EventHandler委托 [
The System.EventHandler delegate expects you to have a method with a specific signature present. See: EventHandler Delegate[^]

So your code should probably be like:
protected void lnkCustomer_Click(object sender, System.EventArgs e)
    {
        ...
    }



加法:
将发件人投射到链接按钮:



Addition:
Casting the sender to link button:

protected void lnkCustomer_Click(object sender, System.EventArgs e)
    {
        LinkButton button = sender as LinkButton;
        if (button.CommandName == "CustomerLink")
           ...
    }


这篇关于'lnkCustomer_Click'的重载不匹配委托'System.EventHandler'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆