Reputation: 53
I have a repeater of LinkButtons and on the ItemCommand event. I need to get the Data Object that created the link button.
My DataSource is List so on ItemCommand I need MyObject object = ???
Upvotes: 3
Views: 3392
Reputation: 35514
Are you looking for this? This will send the ID to the code behind using CommandArgument
so it can be processed.
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("ID") %>' runat="server" CommandName="myCommand">LinkButton</asp:LinkButton>
And in code behind:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "myCommand")
{
string myID = e.CommandArgument.ToString();
}
}
Or you can use CommandArgument='<%# Container.ItemIndex %>'
. Then you know the row number and can access the corresponding index in your source.
Upvotes: 2