Direct click of the button into the table item_databound

3

I have a table inside a repeater. In this table there is a button. What I want is when I click this button, it fires the repeater event: rptGerenciaProcessos_ItemDataBound , just that. How do I do this? My button is this:

<td>
  <asp:Button ID="btnConsultarProcessos" OnClick="btnConsultarProcessos_Click"  runat="server" Text="Consultar processo" CssClass="acessos" />
</td>
    
asked by anonymous 17.11.2014 / 20:39

1 answer

4

From what I understand, you need something like this, right?

protected void rptGerenciaProcessos_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // Procurando o botão no Repeater
    var button = (Button)e.Item.FindControl("btnConsultarProcessos");

    // Verificando senão está nulo.
    if (button == null) return;

    // Associando evento ao botão.
    button.Click += btnConsultarProcessos_Click;

    button.CommandName = "Excluir";
    button.CommandArgument = "1234";
}

protected void btnConsultarProcessos_Click(object sender, EventArgs e)
{
    // Faça algo ...
}   

Or, you can use the Repeater's ItemCommand.

protected void rptGerenciaProcessos_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    // Procurando o botão no Repeater
    var button = (Button)e.Item.FindControl("btnConsultarProcessos");

    // Verificando senão está nulo.
    if (button == null) return;

    if (button.CommandName == "Excluir")
    {
        this.ExcluirRegistro(button.CommandArgument);
    }
}
    
17.11.2014 / 20:53