2013-05-01 51 views

回答

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); 
    } 
+0

如果你看到我的第一個問題,我已經嘗試過了,它讓我異常...添加 – Mathematics 2013-05-01 09:48:21

+0

示例代碼 - 希望它幫助 – Nathan 2013-05-01 09:58:00

+0

+1,我給它一個去,感謝 – Mathematics 2013-05-01 10:02:01

0

請試試這個。

<a href = "#" onclick="alert('Client click event..!')">Detail</a>