Search code examples
c#asp.netrepeater

button click event in repeater control to show data in same repeater in asp.net c#


I have a Button inside a repeater on whose click textbox should be visible to user to enter, but i have a list of button and clicking on specific button textbox should open specifically for that button only,

Currently when i click button all the textboxs gets visible to user.

Here Is The Code....

    <asp:Repeater ID="rpt">
        <div align="right" id="reply">
            <asp:LinkButton ID="lnkbtnreply" OnClick="lnkbtnreply_Click" Text="Reply"></asp:LinkButton>
        </div>

        <asp:TextBox ID=""  placeholder="Enter Your Reply Here" Visible="false">
      </asp:TextBox>
   </asp:Repeater>

Code Behind:

protected void lnkbtnreply_Click(object sender, EventArgs e) 
{ 
       foreach (RepeaterItem item in rptcomment.Items) 
       {
             Panel replypic = (Panel)item.FindControl("replypic");
             Panel replywrite = (Panel)item.FindControl("replywrite");
             replypic.Visible = true; replywrite.Visible = true;
       }
}

Solution

  • I have Found The Answer. In Case You Guys Are Still Searching For It Have A Look :

    Here is the Code Behind:

    protected void rptcomment_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Panel replypic = (Panel)e.Item.FindControl("replypic");
            Panel replywrite = (Panel)e.Item.FindControl("replywrite");
            if (e.CommandName == "img_Click") // check command is cmd_delete
            {
                // get you required value
                string CustomerID = (e.CommandArgument).ToString();
                replypic.Visible = true;
                replywrite.Visible = true;
            }
        }
    }