Direct button click into table item_databound

Asked

Viewed 224 times

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 triggers the Repeater event: rptGerenciaProcessos_ItemDataBound, just that. How do I do it? That’s my button:

<td>
  <asp:Button ID="btnConsultarProcessos" OnClick="btnConsultarProcessos_Click"  runat="server" Text="Consultar processo" CssClass="acessos" />
</td>

1 answer

4


from what I understand you need something like this, no ?

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 Itemcommand from Repeater.

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);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.