Question

Je suis difficile à obtenir une boîte de confirmation JavaScript dans ASP: Buttonfield:

Ceci est le code d'origine de la grilleview, mais Buttonfield ne semble pas accepter "OnClientClick"

<asp:GridView ID="gvNavios" runat="server"  onrowcommand="gvNavios_RowCommand">
<Columns>
    <asp:ButtonField runat="server" ButtonType="Button" Text="delete" CommandName="Eliminar" />
</Columns>
</asp:GridView>

Alors j'ai essayé ASP: Linkbutton à la place:

<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
     <asp:LinkButton ID="eliminar" CommandName="delete" runat="server" Text="delete"/>
</ItemTemplate>
</asp:TemplateField>

Cependant, cette façon, je ne peux pas obtenir quelle ligne a été cliquée car e.commandargument n'est pas rempli

Le C # Code-derrière:

 protected void gvNavios_RowCommand(object sender, GridViewCommandEventArgs e)
{

    string currentCommand = e.CommandName;
    int currentRowIndex = Int32.Parse(e.CommandArgument.ToString());
    string imo = gvNavios.Rows[currentRowIndex].Cells[3].Text;

    if (currentCommand.Equals("delete"))
    {
        eliminarNavio(imo);
        Response.Redirect(Request.RawUrl);
    }

}

J'apprécie l'une des opérations suivantes: Insérez JavaScript dans le bouton ASP: ou obtenez le numéro de ligne de LinkButton.

Était-ce utile?

La solution

Vous devez ajouter le CommandArdgument au Linkbutton et fournir un index (l'identifiant d'objet sera le meilleur).

<asp:LinkButton ID="eliminar" CommandArgument='<%# Eval("ID") %>' CommandName="delete" runat="server" Text="delete"/>

Autres conseils

Porque no USAS UN TEMPLAYFIELD?, Creo Es Mass Facile

Pourquoi n'utilisez-vous pas un templatefield? ¿

à l'intérieur du Rowdatabound :

Créez d'abord un Templatefield, puis à l'intérieur de la templatefield Insérer une imageButton, appelez-le img_borrar (CommandName).

Puis dans le RowCommand, trouvez-le, définissez l'index (CommandArdGument), définissez un style et la confirmation Java:

If e.Row.RowType = DataControlRowType.DataRow Then
                Dim boton_borrar As ImageButton = CType(e.Row.Cells(1).FindControl("img_borrar"), ImageButton)
                boton_borrar .CommandArgument = e.Row.RowIndex.ToString
                boton_borrar .Style("cursor") = "hand"
                boton_borrar .Attributes.Add("onClick", "return window.confirm(' ¿Desea borrar este registro? ');")


            End If

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top