Access textbox in itemtemplate

Posted by  Ashish Pandey
 1355  View(s)
Rate this:

I have 2 textboxes and a button in a row, and a Repeater dynamically generates some rows at Page_Load function.

<asp:Repeater id="Repeater1" runat="server">
            <td><asp:Label CssClass="form-control" disabled="true" runat="server"><%# DataBinder.Eval(Container.DataItem, "sid") %></asp:Label></td>
            <td><asp:TextBox CssClass="form-control" runat="server" ID="quiz1"></asp:TextBox></td>
            <td><asp:TextBox CssClass="form-control" runat="server" ID="quiz2"></asp:TextBox></td>
            <td><asp:Button ID="add" CommandName="add" runat="server" OnClick="addQuiz" Text="Add" CssClass="btn btn-success btn-sm form-control"/></td>

How do I access the textboxes in the Repeater upon clicking the button in the row?

  1. Re: Access textbox in itemtemplate

    Hi Ashish, 

    try this:

    protected void addQuiz(Object sender, EventArgs e)
        var btn = (Button) sender;
        var item =(RepeaterItem) btn.NamingContainer;
        var quiz1 =(TextBox) item.FindControl("quiz1");
        var quiz2 =(TextBox) item.FindControl("quiz2");

      Modified On Apr-04-2018 05:59:33 AM