Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Cancellare valori da checkbox

    ho questa checkbox dentro la gridview:
    codice:
                   <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox ID="SelectedItem" AutoPostBack="true" runat="server" OnCheckedChanged="SelectedItems_CheckedChanged" />
                        </ItemTemplate>
                    </asp:TemplateField>
    ho messu un pulsanre che dovrebbe richiamare un evento per cancellare tutte li righe selezionate:
    codice:
            protected void Button3_Click(object sender, EventArgs e)
            {
                foreach (GridViewRow row in DecoderView.Rows)
                {
                    CheckBox checkbox = (CheckBox)row.FindControl("SelectedItem");
                    if (checkbox.Checked)
                    {
                        richiamare_il_DeleteCommand
                    }
                }
            }
    come faccio a richiamare il DeleteCommand del datasource?:
    codice:
        <asp:SqlDataSource ID="DecoderSql" runat="server" ConnectionString="<%$ ConnectionStrings:MYTELENEWS %>"
            DeleteCommand="DELETE FROM siti WHERE sito# = @sito#">
            <DeleteParameters>
                <asp:Parameter Name="sito#" />
            </DeleteParameters>
        </asp:SqlDataSource>

  2. #2
    fatto anche questa va:
    codice:
            protected void Button3_Click(object sender, EventArgs e)
            {
                foreach (GridViewRow row in DecoderView.Rows)
                {
                    CheckBox checkbox = (CheckBox)row.FindControl("SelectedItem");
                    if (checkbox.Checked)
                    {
                        int id = Convert.ToInt32(DecoderView.DataKeys[row.RowIndex].Value);
                        DecoderSql.DeleteParameters["sito#"].DefaultValue = id.ToString();
                        DecoderSql.Delete();
                    }
                }
            }
    DecoderView è la gridview.
    SelectedItem è la checkbox.
    il metodo per la cancellazione l'ho aggiunto da modalità design.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.