Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a functional link in a Repeater control

I am implementing a Repeater in my web application to display data. I want to add functional action links in a column similar to the built-in functionality in a GridView. Can anybody give me the steps required? I assume I will add a LinkButton control to each row, somehow set the OnClick event handler to point to the same method, and somehow pass in the unique identifier on the row as a parameter.

Thanks!

like image 480
Mike Cole Avatar asked May 09 '26 03:05

Mike Cole


1 Answers

I'm guessing this is what you want.

    <asp:Repeater ID="rpt" runat="server">
        <ItemTemplate>
            <asp:LinkButton ID="lbtn" runat="server" OnCommand="lbtn_Command" 
            CommandArgument='<%# DataBinder.Eval(Container.DataItem, "KeyIDColumn") %>' ></asp:LinkButton>
        </ItemTemplate>
    </asp:Repeater>

Then in your code behind

protected void lbtn_Command(object sender, CommandEventArgs e)
{
    int id = Convert.ToInt32(e.CommandArgument);
}
like image 168
Eoin Campbell Avatar answered May 11 '26 14:05

Eoin Campbell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!