Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding linkbuttons to datalist 1

Status
Not open for further replies.

drew10

Programmer
Feb 26, 2002
123
US
I have a datalist that provides membership info. The datalist has several records. What I would like to do is create a linkbutton for each username in the datalist. When the linkbutton is clicked, I would like to fire a subroutine. My code looks like this:
Code:
<ItemTemplate>
  <table>
    <tr>
      <td><asp:linkbutton runat=server><%# DataBinder.eval(Container.DataItem, &quot;userName&quot;)%></asp:linkbutton></td>
    </tr>
  </table>
</ItemTemplate>
Ideally, what I would like to do is add an onclick event that passes a commandArgument to the subRoutine. Can anyone give me some tips on how to accomplish this?

thanx,
drew
 
<asp:linkbutton runat=server commandArgument=<%# Container.DataItem(&quot;userName&quot;) onCommand=commandHandler><%# Container.DataItem(&quot;userName&quot;)%></asp:linkbutton>

This should work for you. Also, I can't remember exactly which situations where you HAVE to use databinder.eval, but it causes late-binding, and you want to avoid that if at all possible (performance).

I don't think you will need it in this case, so I removed it from the code there.
penny1.gif
penny1.gif
 
Ok, I've gotten that far, but I'm still unclear about how to capture the commandargument in a subroutine. Is the commandHandler the name of the sub? What parameters are passed to the sub? I've tried:

Public sub linkClicked(ByVal sender as sender.object, byVal e as commandEventArgs)

End Sub

but I keept getting an error saying &quot;sub does not have the same signature as delegtate 'Delegate Sub EventHandler(sender as object, e as system.eventArgs)'&quot;
 
Let's see (just soes I'm clear) the current version of your datalist code, accompanied by the event handler that is returning you that error...

Also, is it a compile time, or a run time error?

paul
penny1.gif
penny1.gif
 
Sorry, I should have posted that I figured this one out. My problem was that I was trying the onclick event along with the oncommand. After removing my onclick=linkClicked everything works smoothly. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top