Clickable labels

P

Peter Kirk

Hi

how do I create a "link" which calls a method in my code behind?

I have a repeater which shows a table of results, and some of the cells in
the table need to be clickable and cause things to happen.

Could be something like the following I want (doesn't work of course). Here
I try to create a cell with a clickable label which calls the method
MyMethod in my code behind, passing the id of the clicked row.


<asp:repeater id="ResultsRepeater" Runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="voyagelabel" Runat="server"
text="<%# ((DataRow)Container.DataItem).Name %>">
onclick="MyMethod(<%# ((DataRow)Container.DataItem).Id
%>)">
</asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:repeater>



Peter
 
S

Steve C. Orr [MVP, MCSD]

I think you should use a LinkButton control instead of trying to reinvent
the wheel by hacking the label control.
 
P

Peter Kirk

Steve C. Orr said:
I think you should use a LinkButton control instead of trying to reinvent
the wheel by hacking the label control.

Yes, I eventually came to the same realisation. However, I can't get the
link button (which is created dynamically in the repeater) to fire a call to
the "click" method in the code behind....
 
D

Demetri

Use the Repeater's ItemCommand event. When the linkbutton is clicked the
ItemCommand event of the repeater will fire and pass event args specifying
what CommandName is passed via the LinkButton's CommandName attribute.

Hope that makes sense, otherwise check out ItemCommand on MSDN for the
Repeater control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top