在gridview中动态的添加复选框checkbox

首先是前台的页面:

<asp:GridView ID="gvbianmai" runat="server" AutoGenerateColumns="False"
                    Height="57px" Width="611px" AllowPaging="True" PageSize="5">
                    <Columns>
                        <asp:TemplateField HeaderText="选择项">
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server" DataField="id"/>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="id" HeaderText="生产线编号" />
                        <asp:BoundField DataField="roomtype" HeaderText="所属厂房" />
                        <asp:BoundField DataField="linetype" HeaderText="生产线类型" />
                        <asp:BoundField DataField="proname" HeaderText="产品类型" />
                        <asp:BoundField DataField="starseason" HeaderText="开建时间" />
                        <asp:TemplateField HeaderText="净值">
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text="5"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

 

后台cs文件:

  gvbianmai.DataSource = ds2;
            gvbianmai.DataBind();

 

 

 

 

foreach (GridViewRow gvr in gvbianmai.Rows)
        {
            CheckBox ch = (CheckBox)gvr.FindControl("CheckBox1");
            if (ch.Checked)
            {
                int nID = int.Parse(gvr.Cells[1].Text);
                result = bllnewline.bianmai(nID);
            }
        }

posted @ 2010-05-06 08:16  j2ee技术  阅读(290)  评论(0编辑  收藏  举报