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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.