Reputation: 5920
I have a repeater and it has an Asp button. I want to get repeater item which contains clicked button.
Here is a part of my repeater:
...
<td>
<asp:Button runat="server" ID="btnSaveStock" OnClick="btnSaveStock_OnClick" Text="Save" />
</td>
</tr>
</ItemTemplate>
I want to access repeater item in here :
protected void btnSaveStock_OnClick(object sender, EventArgs e)
{
try
{
Button btnSaveStock = (Button)sender;
Repeater rptProductChance = (Repeater)btnSaveStock.Parent;
}
catch (Exception)
{
throw;
}
}
What should I do expect loop as check all items of repeater?
Upvotes: 0
Views: 2822
Reputation: 4892
This is what you can do. You can access the RepeaterItem
by casting the buttons NamingContainer
.
protected void btnSaveStock_OnClick(object sender, EventArgs e)
{
try
{
Button btnSaveStock = (Button)sender;
RepeaterItem item = (RepeaterItem)btnSaveStock.NamingContainer;
//....
}
catch (Exception)
{
throw;
}
}
Upvotes: 1
Reputation: 27852
Since there are many buttons (not just one), if you want to deal with handling the button click ~in context of the current "row" of the repeater~, you probably want to wire up to the Repeater, not the button "template definition".
Upvotes: 0