gridview中填充的复选框列

时间:2014-09-08 06:49:55

标签: c# asp.net sql-server gridview checkbox

我在gridview中填充了8列作为复选框。我需要知道如何从中获取值并使用C#将它们存储在数据库中。请帮助。

aspx代码:

<asp:GridView ID="GridView1" runat="server" CssClass="etable" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="rollnumber" HeaderText="Roll Number" />
        <asp:BoundField DataField="name" HeaderText="Name" />
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="IBM">
            <ItemTemplate>
                <asp:CheckBox ID="chkibm" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="FOL">
            <ItemTemplate>
                <asp:CheckBox ID="chkfol" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="IS">
            <ItemTemplate>
                <asp:CheckBox ID="chkis" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="CP">
            <ItemTemplate>
                <asp:CheckBox ID="chkcp" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="WIM">
            <ItemTemplate>
                <asp:CheckBox ID="chkwim" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="STTPO">
            <ItemTemplate>
                <asp:CheckBox ID="chksttpo" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="TDM">
            <ItemTemplate>
                <asp:CheckBox ID="chktdm" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="PA">
            <ItemTemplate>
                <asp:CheckBox ID="chkpa" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="ID Card">
            <ItemTemplate>
                <asp:CheckBox ID="chkid" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

1 个答案:

答案 0 :(得分:0)

如果CheckBox字段位于database,请使用此

<asp:CheckBoxField DataField="IBM" HeaderText="IBM"/>

而不是

 <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="IBM">
            <ItemTemplate>
                <asp:CheckBox ID="chkibm" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>