0

如何onClientClick向此添加事件

<a href="javascript:__doPostBack('ctl00$m$g_8dbaa58f_d132_4042_b180_3c555d885dde$ctl00$GridView1','Delete$0')">Delete</a>

由于它是一个命令字段,Gridview所以我无法直接获取它,请查看此问题以获取更多信息

4

2 回答 2

1

订阅 gridview 的 RowDataBound 事件并在项目的 Controls 集合中搜索锚标记。

    protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        // this will apply the action in the lambda expression to all controls or sub-controls of the row matching type LinkButton  
        // (you may have a different control type and you may want to alter your lambda expression to check that the control matched is really the control you want to manipulate)
        SearchControls<LinkButton>(e.Row, button => button.OnClientClick = "alert('here');");
    }

    // recursive Control search function
    private void SearchControls<T>(Control start, Action<T> itemMatch)
    {
        foreach (var c in start.Controls.OfType<T>())
            itemMatch(c);

        foreach (var c in start.Controls.OfType<Control>())
            SearchControls<T>(c, itemMatch);
    }
于 2013-05-01T09:46:37.637 回答
0

请试试这个。

<a href = "#" onclick="alert('Client click event..!')">Detail</a>
于 2013-05-01T10:34:02.077 回答