通过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");
    }
}

  

posted @ 2011-09-23 14:13  沙茶叶  阅读(354)  评论(0编辑  收藏  举报