使用自定义数据源在GridView中启用多个选择

时间:2013-04-11 12:59:34

标签: c# asp.net gridview webforms

我有GridView使用自定义数据源:

<asp:ScriptManager ID="DateManager" runat="server" />

<asp:UpdatePanel ID="setDate" runat="server" 
    UpdateMode="Conditional" 
    ChildrenAsTriggers="true">
    <ContentTemplate>
        <asp:GridView ID="res" runat="server" 
            AutoGenerateColumns="False"
            CellPadding="4"
            ForeColor="#333333"
            GridLines="None"
            Width="600px" 
            AllowPaging="True">
            <AlternatingRowStyle BackColor="White" />

            <Columns>
                <asp:BoundField DataField="Ty" HeaderText="Type" />
                <asp:BoundField DataField="time" HeaderText="Time" />
                <asp:BoundField DataField="duration" HeaderText="Duration" />
                <asp:BoundField DataField="confirmed" HeaderText="Status" />
                <asp:CommandField SelectText="SelectIt" ShowSelectButton="True" />
            </Columns>

            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

如何在其上启用多项选择?

1 个答案:

答案 0 :(得分:1)

您可以在每行中添加CheckBox,如下面的代码,并选择多行。

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

有关详细信息,请查看以下文章:Article1 Article2