在gridview中更改buttonfield的背景和前景色

时间:2014-04-07 06:58:41

标签: c# asp.net gridview

我有一个GridView我要更改ButtonField样式以匹配我的网格样式。这是我的GridView

<asp:GridView ID="GridView1" runat="server" Width="936px" AllowPaging="True" AutoGenerateColumns="False"
    CellPadding="4" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand"
    ForeColor="#333333" GridLines="None" Style="text-align: center">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:BoundField DataField="TaskId" HeaderText="TaskId" InsertVisible="False" ReadOnly="True"
            SortExpression="TaskId" />
        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
        <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" Visible="false" />
        <asp:BoundField DataField="Reward" HeaderText="Reward(Rs)" SortExpression="Reward" />
        <asp:BoundField DataField="TimeAllotted" HeaderText="Time(Min)" SortExpression="TimeAllotted" />
        <asp:BoundField DataField="PosterName" HeaderText="Uploader" SortExpression="PosterName" />
        <asp:ButtonField ButtonType="Button" CommandName="Select" Text="Perform Task" />
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle ForeColor="White" HorizontalAlign="Center" BackColor="#2461BF" />
    <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>

我尝试使用BackColorForeColor属性,但它们不是ButtonField的有效属性。

1 个答案:

答案 0 :(得分:0)

尝试使用ControlStyle-BackColor,如下所示:

<asp:ButtonField ButtonType="Button" CommandName="Select" Text="Perform Task" ControlStyle-BackColor="LightBlue" />