top of page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">     
        <asp:GridView ID="GridView1" runat="server">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Cod" HeaderText="FAC_IDUNICO" />
                <asp:BoundField DataField="Cod2" HeaderText="FAC_STATUS" />
                <asp:BoundField DataField="Cod3" HeaderText="FAC_NOME" />
            </Columns>           
        </asp:GridView>       
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="excluir" />     
    </form>
</body>
</html>

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



protected void Page_Load(object sender, EventArgs e)

    {

        if (dt.Rows.Count < 3)
        {
            dt.Columns.Add("Cod", System.Type.GetType("System.String"));
            dt.Columns.Add("Cod2", System.Type.GetType("System.String"));
            dt.Columns.Add("Cod3", System.Type.GetType("System.String"));
            for (int i = 1; i < 10; i++)
            {
                dt.Rows.Add(new String[] { i.ToString(), "Coluna 2", "Coluna 3" });
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }       
    }





protected void Button2_Click(object sender, EventArgs e)

    {       
        CheckBox chbox;
        Label lb;
        ArrayList iIndices = new ArrayList();
        int i = 0;
        foreach(GridViewRow row in GridView1.Rows)
        {
            chbox = (CheckBox)row.FindControl("CheckBox2");
            //lb = (Label)row.FindControl("Cod");
           
            if (chbox.Checked == true)
            {
                iIndices.Add(row.Cells[1].Text);
                DataRow filteredRows = dt.Select("Cod = " + iIndices[i]).FirstOrDefault();
                dt.Rows.Remove(filteredRows);
                i++;

             
            }           
        }
        //for (int i = 0; i < iIndices.Count; i++)
        //{
           
        //    //DataRow[] dr = dt.Select("Cod = " + iIndices[i]);
        //    DataRow filteredRows = dt.Select("Cod = " + iIndices[i]).FirstOrDefault();
        //    dt.Rows.Remove(filteredRows);      
        //}
       
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }



bottom of page