通过CheckBox获取当前行记录

XHTML:

<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false" CellSpacing="0" DataKeyNames="CarId"

    CellPadding="0" BorderWidth="0" GridLines="None" >

    <Columns>

        <asp:TemplateField HeaderText="序号">

            <ItemTemplate>

                <asp:CheckBox runat="server" ID="cbSelect" name="cbSelect" AutoPostBack="true" 

                    OnCheckedChanged="cbSelect_CheckedChanged" />

                <%#Container.DataItemIndex+1%>.

            </ItemTemplate>

        </asp:TemplateField>

    </Columns>

</asp:GridView>

.cs:

protected void cbSelect_CheckedChanged(object sendar, EventArgs e)

{

    CheckBox cbSelect = (CheckBox)sendar;

    GridViewRow gvRow = (GridViewRow)((CheckBox)sendar).Parent.Parent;

            

    if (cbSelect != null)

    {

        // Code here ……

        TextBox txtQuantity = (TextBox)gvRow.FindControl("txtQuantity");

    }

}

  

你可能感兴趣的:(checkbox)