Reputation: 28545
I have a repeater bound to a datasource, in the itemtemplate for the repeater i have a link button
im using stuff like:
<%# Eval("myfield") %>
to get data for the item.i need a linkbutton in there that when clicked I can access all the properties relevant to that item in the onclick event handler in the backend.
how do i access the other properties of a paticular item, when a button within the itemtemplate is clicked.
thanks
Upvotes: 3
Views: 320
Reputation: 9541
You could either:
Pass the ID of the object as a CommandArgument, then reload it in the code behind
<asp:LinkButton runat="server" OnCommand="MyButton_Command" CommandArgument='<%# Eval("MyObjectId") %>'/>
protected void MyButton_Command(object sender, CommandEventArgs e)
{
int myId = int.Parse(e.CommandArgument.ToString());
// Load the object using the id passed in
}
or
Cast "sender" to the LinkButton, which will give you access to the RepeaterItem and any other controls in there ...violently throws up at the thought of even suggesting it
Upvotes: 1