简体   繁体   中英

How to find the index of selected row by checkbox in gridview?

I have a gridview with 2 column then cell[0] has checkbox and cell[1] has data I want if checkbox checked and click button delete, find which the checkbox is checked and delete the the row.

 <asp:GridView ID="GridView1" runat="server"  AutoGenerateColumns="False" BackColor="White"
         BorderColor="Blue" BorderStyle="Solid" CellPadding="3" DataSourceID="SqlDataSource1"
         ForeColor="Black"  GridLines="Vertical" Width="656px" >
        <AlternatingRowStyle BackColor="#CCCCCC" />
        <Columns>
             <asp:TemplateField>

                 <ItemTemplate>

                     <asp:CheckBox  runat="server" />
                 </ItemTemplate>``
             </asp:TemplateField>
            <asp:BoundField DataField="picname" HeaderText="picname" SortExpression="picname" />
        </Columns>
        <FooterStyle BackColor="#CCCCCC" />
        <HeaderStyle BackColor="#99FF66" Font-Bold="True" ForeColor="Black" BorderColor="#006600" />
        <PagerStyle BackColor="#33CC33" ForeColor="#0066FF" HorizontalAlign="Center" BorderStyle="Dashed" />
        <RowStyle BackColor="Lime" />
        <SelectedRowStyle BackColor="#0066CC" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#808080" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#383838" />
    </asp:GridView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM