ItayM
ItayM

Reputation: 912

Repeater Internal TextBox in "OnCommand" event

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

Answers (1)

KV Prajapati
KV Prajapati

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

Related Questions