右对齐GridView中包含数字的所有列(值)

时间:2014-08-30 06:53:46

标签: css asp.net

我想右对齐包含数字值的所有列(仅限值),但我找不到确切的解决方案。

我使用非常简单的aspx页面和皮肤文件如下:

<asp:GridView SkinID="MyGrid" runat="server"  CssClass="GridHeader" Width="800px" CellPadding="4">
        <FooterStyle BackColor="#336699" Font-Bold="True" ForeColor="White"  />
        <PagerStyle BackColor="#336699" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
        <PagerSettings PageButtonCount="40" />
</asp:GridView>   

将标题居中的Css文件(标题)

.GridHeader caption
{
    color:White;
    background-color:#6299c5;
    font-weight:bold;
    text-align:left;
    border-bottom: 1px solid white;
    padding:5px;
}
.GridHeader th, .GridHeader th a 
{
    text-align:center;
    background-color:#336699;
    color:White;
    font-weight:200;
}

aspx文件中的GridView

<asp:GridView ID="gvCashbookAFA" runat="server" SkinID="MyGrid" Width="100%" AutoGenerateColumns="False"
                        DataSourceID="objgvCashbookAFA" AllowSorting="True" AllowPaging="True" 
                        PageSize="50" onpageindexchanging="gvCashbookAFA_PageIndexChanging">
                        <Columns>
                            <asp:BoundField DataField="No" HeaderText="No" SortExpression="No" ReadOnly="True" />
                            <asp:BoundField DataField="ReferenceNumber" HeaderText="Ref #" SortExpression="ReferenceNumber" />
                            <asp:BoundField DataField="TransactionType" HeaderText="Transaction Type" SortExpression="TransactionType" />
                            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                            <asp:BoundField DataField="Donor" HeaderText="Donor" SortExpression="Donor"></asp:BoundField>
                            <asp:BoundField DataField="OrderDate" HeaderText="Order Date" SortExpression="OrderDate"
                                DataFormatString="{0:dd-MMM-yyyy}" HtmlEncode="False" />
                            <asp:BoundField DataField="Debit" HeaderText="Debit" ReadOnly="True" SortExpression="Debit"
                                DataFormatString="{0:N2}" HtmlEncode="False" >
                            <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Credit" HeaderText="Credit" SortExpression="Credit" 
                                DataFormatString="{0:N2}" >
                            <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                            <asp:BoundField DataField="Balance" HeaderText="Balance" ReadOnly="True" SortExpression="Balance"
                                DataFormatString="{0:N2}" HtmlEncode="False" >
                            <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                        </Columns>
                    </asp:GridView>

数字列非常清晰,我也将ItemStyle应用于这些列,但它不起作用。

如何将列与数字对齐?

谢谢!

1 个答案:

答案 0 :(得分:0)

    <asp:BoundField DataField="Debit" HeaderText="Debit" ReadOnly="True" SortExpression="Debit" DataFormatString="{0:N2}" HtmlEncode="False" ItemStyle-HorizontalAlign ="Right"  >
</asp:BoundField>