Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

repeater control - get values

I have a repeater control laid out as shown in the code attached.

Now, if the user clicks on the lnkRemoveCategory button I need the value of "Path" passed to a asp.net code procedure so that I can do some stuff.

How?
<asp:Repeater ID="rpCategories" runat="server">
                                        <ItemTemplate>                                                                         
                                           <font size="2"><%#Eval("Path")%> &nbsp;&nbsp;&nbsp;&nbsp;
                                               <asp:LinkButton ID="lnkRemoveCategory" runat="server">Remove</asp:LinkButton></font> 
                                           <hr />
                                     
                                    </ItemTemplate>
                                
                                </asp:Repeater>

Open in new window

Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

You can set the CommandArgument of the LinkButton to <%# Eval("Path") %>, and then handle the LinkButton's "Command" event.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.commandargument.aspx#Y760

<script runat="server">
    private void lnkRemoveCategory_Command(object sender, CommandEventArgs e)
    {
        string path = (string)e.CommandArgument;
    }
</script>

<asp:Repeater ID="rpCategories" runat="server">
  <ItemTemplate>                                                                         
      <font size="2"><%#Eval("Path")%> &nbsp;&nbsp;&nbsp;&nbsp;
      <asp:LinkButton ID="lnkRemoveCategory" runat="server" CommandArgument='<%# Eval("Path") %>' OnCommand="lnkRemoveCategory_Command">Remove</asp:LinkButton></font> 
      <hr />                                  
  </ItemTemplate>                                
</asp:Repeater>

Open in new window

Avatar of vbnetcoder
vbnetcoder

ASKER

Could it call a code behind function?
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!