0

我拥有的 gridview 以 SQLDataSource 为界。我想为填充的每一行添加一个复选框。我该如何做到这一点,以及在选中/取消选中时如何让复选框回发?

这是我的网格视图代码:

<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>         
4

1 回答 1

2

在你的gridview中放一个这样的templateField

<asp:TemplateField>
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" />
    </ItemTemplate>
</asp:TemplateField>
于 2012-07-19T19:34:18.447 回答