我正在尝试将bootstrap活动类添加到asp.net gridview行

时间:2015-01-29 17:18:33

标签: asp.net c#-4.0 gridview twitter-bootstrap-3

我正在尝试将活动类添加到GridView。一旦我在网格中选择了一行,我想使用Bootstrap将其设置为选中。之前人们可能会问过它。但我找不到这个。

GridView的:

<div class="row">
    <asp:UpdatePanel ID="UpdatePanelGrid" runat="server">
        <ContentTemplate>
            <div class="history-table ">
                <asp:GridView CssClass="col-lg-6 col-md-8 col-sm-10 col-xs-12" DataKeyNames="HistoryId" ID="gvFunds" runat="server"
                    AutoGenerateColumns="False" OnSelectedIndexChanged="gvFunds_SelectedIndexChanged" OnRowDataBound="gvFunds_RowDataBound">
                    <Columns>
                        <asp:BoundField DataField="HistoryId" Visible="false" />
                        <asp:BoundField DataField="Date" HeaderText="Date" ReadOnly="True" />
                        <asp:BoundField DataField="Time" HeaderText="Time" ReadOnly="True" />
                        <asp:BoundField DataField="UserId" HeaderText="User ID" ReadOnly="True" />
                    </Columns>
                </asp:GridView>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

CSS:

.history-table table {
    text-align: center;
    border: none;
}

    .history-table table tr:nth-child(2n+1) {
        background-color: #C6C0AA;
    }

    .history-table table tr th {
        text-align: center;
        height: 35px;
        border: none;
        background-color: #C6C0AA;
    }

    .history-table table td {
        height: 25px;
        border: none;
    }

    .history-table table tr:hover {
        background-color: #8A2A2A;
        color: #FFF;
        cursor: pointer;
    }

    .history-table table tr:first-child:hover {
        color: #000;
    }

1 个答案:

答案 0 :(得分:0)

在尝试了很多方法后,我得到了答案。我可以使用GridView属性轻松完成。我在此分享以供您参考。

<div class="row" style="margin: 0px;">
        <asp:UpdatePanel ID="UpdatePanelGrid" runat="server">
            <ContentTemplate>
                <div class="gridview-table ">
                    <asp:GridView CssClass="col-xs-12 gridview-with-default-selected-row" DataKeyNames="HistoryId" ID="gvFunds" ClientIDMode="Static" runat="server" ViewStateMode = "Enabled"
                        AutoGenerateColumns="False" OnSelectedIndexChanged="gvFunds_SelectedIndexChanged" OnRowDataBound="gvFunds_RowDataBound">
                        <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
                        <SelectedRowStyle Font-Bold="True" BackColor="#8a2a2a" ForeColor="White"></SelectedRowStyle>
                        <AlternatingRowStyle BackColor="White" ForeColor="Black" />
                        <RowStyle BackColor="#CDC7B1" BorderStyle="None" Height="30px" ></RowStyle>
                        <HeaderStyle Height="30px" BackColor="#F5F4EF" BorderColor="#F5F4EF" Font-Names="vegurregular" Font-Size="12px" Font-Bold="False"></HeaderStyle>
                        <Columns>
                            <asp:BoundField DataField="HistoryId" HeaderText="History ID" />
                            <asp:BoundField DataField="Date" HeaderText="Date" ReadOnly="True" />
                            <asp:BoundField DataField="Time" HeaderText="Time" ReadOnly="True" />
                            <asp:BoundField DataField="UserId" HeaderText="User ID" ReadOnly="True" />
                        </Columns>
                    </asp:GridView>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>