如何将无界复选框列添加到与数据源有界的网格视图中?

时间:2012-07-19 19:28:38

标签: c# asp.net

我的gridview受到SQLDataSource的限制。我想为每个填充的行添加一个复选框。如何执行此操作以及如何在选中/取消选中时复选框回发?

这是我的gridview代码:

<asp:GridView ID="GridView2" runat="server" CellPadding="3"
        ForeColor="#333333" GridLines="None" DataSourceID="dsWarningDay" 
        AllowSorting="True" SortedAscendingHeaderStyle-CssClass="sortasc-header" 
        SortedDescendingHeaderStyle-CssClass="sortdesc-header"
        AllowPaging="True" PageSize="17" PagerSettings-Mode="NextPreviousFirstLast" 
        ShowHeaderWhenEmpty="True" PagerStyle-Font-Names="WebDings" PagerStyle-Font-Size="Medium"
        PagerSettings-FirstPageText=" 7 " PagerSettings-PreviousPageText=" 3 " 
        PagerSettings-NextPageText=" 4 " PagerSettings-LastPageText=" 8 " 
          Font-Size="Small">
        <AlternatingRowStyle BackColor="White" ForeColor="#333333" />
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<PagerSettings FirstPageText=" 7 " LastPageText=" 8 " Mode="NextPreviousFirstLast" NextPageText=" 4 " PreviousPageText=" 3 "></PagerSettings>

        <PagerStyle BackColor="#5D7B9D" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#DCE2E8" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

<SortedAscendingHeaderStyle CssClass="sortasc-header"></SortedAscendingHeaderStyle>

<SortedDescendingHeaderStyle CssClass="sortdesc-header"></SortedDescendingHeaderStyle>
     </asp:GridView>         

1 个答案:

答案 0 :(得分:2)

你的gridview中的

放了一个像这样的templateField

<asp:TemplateField>
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" />
    </ItemTemplate>
</asp:TemplateField>