If you want to set JS code for each individual gridview element in a RowDataBound event, you can add hyperlink control to your ItemTemplate and set the NavigationUrl property of this control in JS
<ItemTemplate> <asp:Hyperlink runat="server" id="lnk" ImageUrl="..."/> ... </ItemTemplate>
RowDataBound-EventHandler:
... if (e.Row.RowType != DataControlRowType.DataRow) return; string js = String.Format("javascript:ShowChildGrid('div{0}');", rowId); var lnk = e.Row.FindControl("lnk") as Hyperlink; if(lnk!=null) { lnk.NavigationUrl = js; lnk.ImageUrl = ...; }
Of course, you can also use a and img with runat -Attribute
Stephan bauer
source share