Sunday, September 5, 2010

Fire ItemCommand event of repeater from <div> click or <tr> click using javascript

HTML:-

<asp:Repeater ID="rpt" runat="server" OnItemCommand="rpt_ItemCommand" OnItemCreated="rpt_ItemCreated">
<HeaderTemplate>
<table width="100%" cellpadding="0" cellspacing="0">
</HeaderTemplate>
<ItemTemplate>
<tr onclick='javascript:FireItemCommand(<%#DataBinder.Eval(Container, "ItemIndex", "")%>)'
style="cursor: pointer">
<td>
<%# Eval("Name") %>
</td>
<td>
<asp:LinkButton ID="lnkDim" runat="server" Text="lnk123" CommandArgument='<%# Eval("Name") %>'></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

Javascript:-
function FireItemCommand(index) {

__doPostBack('rpt$ctl0' + parseInt(index + 1).toString() + '$lnkDim', '');

}

1 comment:

Don Gibson said...

Thanks!!!! Saved me a ton of time working this one out! Works great.