Reputation: 912
I have Repeater with LinkButton with ID CommandArgument When I click that button, I want to get the Value from the Same DataItem TextBox Inside the repeater. How can I make it Easily. Thanks
Upvotes: 0
Views: 2108
Reputation: 94653
You have to handle the ItemCommand
event of Repeater control.
Markup:
<asp:Repeater ID="Repeater1" runat="server"
onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>
<asp:LinkButton
ID="LinkButton1"
runat="server"
CommandName="cmd"
CommandArgument='<%#Eval("Name") %>'
Text="Click Here"
>
</asp:LinkButton>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>
Code:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "cmd")
{
TextBox tx = e.Item.FindControl("TextBox1") as TextBox;
tx.Text = e.CommandArgument.ToString();
}
}
Upvotes: 4