I'm feeding a webform with textboxes and buttons from a repeater, according to the tuples (people table) returned in an SQL query, linking the code to specific attributes within those controls. For the textbox I'm using the hidden attribute, while for the buttons I'm using the CommandArgument attribute in order to use it with the OnCommand method. Now I need in the OnCommand method to identify which textbox (hidden attribute) corresponds to the linked CommandArgument so that I can insert information into my database. Is there any way to do this check or even an easier way to achieve that my goal?
My repeater:
<div class="col-md-6" runat="server">
<asp:Repeater ID="rptControles" runat="server">
<ItemTemplate>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div id="formulario" class="input-group" runat="server">
<asp:TextBox ID="txtURL" class="form-control" hidden='<%# DataBinder.Eval(Container.DataItem, "pes_codigo") %>' placeholder='<%# DataBinder.Eval(Container.DataItem, "pes_nome") %>' runat="server"></asp:TextBox>
<span class="input-group-btn">
<asp:Button ID="btnValidar" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pes_codigo") %>' OnCommand="btnValidar_Command" CssClass="btn btn-default" runat="server" Text="Go!" CausesValidation="false" />
</span>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
populaFormulario(Convert.ToInt32(Session["codigo_evento"]));
}
populaFormula:
public void populaFormulario(int codigoEvento)
{
ParticipanteDB parDB = new ParticipanteDB();
rptControles.DataSource = parDB.SelecionarParticipantes(codigoEvento).Tables[0].DefaultView;
rptControles.DataBind();
}
btnValidar_Command:
protected void btnValidar_Command(object sender, CommandEventArgs e)
{
var button = (Button)sender;
var textbox = (TextBox)button.Parent.FindControl("txtURL");
TextBox1.Text = e.CommandArgument.ToString() + " - " + textbox.Text;
}
Example of return of textboxes and buttons: