在GridView中对齐行值

时间:2010-06-21 14:48:53

标签: c# asp.net .net-3.5 gridview

我需要在asp.net 3.5中的gridview列中右对齐值 我怎么能这样做?

                                <asp:GridView ID="gvSearchResults" runat="server" 
                                onpageindexchanging="gvSearchResults_PageIndexChanging" AutoGenerateColumns="False" 
                                CssClass="Grid" AllowPaging="True" PageSize="20" ForeColor="#333333" 
                                GridLines="None" Width="99%" Font-Names="Arial" Font-Size="Small">
                            <Columns>
                            <asp:HyperLinkField Text="Vendor Number" DataNavigateUrlFields="RecID" DataNavigateUrlFormatString="~/Apps/DataForms/Processor/ProcPanel.aspx?RecID={0}" DataTextField="VendorNum">
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:HyperLinkField>
                                <asp:BoundField DataField="VendorName" HeaderText="Vendor Name" HtmlEncode="False" ItemStyle-HorizontalAlign="Left"></asp:BoundField>
                                <asp:BoundField DataField="InvoiceNum" HeaderText="Invoice Number" HtmlEncode="False"></asp:BoundField>
                                <asp:BoundField DataField="InvoiceTot" HeaderText="Invoice Total" HtmlEncode="False" DataFormatString="${0:0,0.00}"></asp:BoundField>
                                <asp:BoundField DataField="InvoiceDate" HeaderText="Invoice Date"  HtmlEncode="False"></asp:BoundField>
                                <asp:BoundField DataField="InvoiceApprover" HeaderText="Invoice Approver"  HtmlEncode="False"></asp:BoundField>
                            </Columns>
                                <RowStyle BackColor="#FFFBD6" ForeColor="#333333"/>
                                <FooterStyle CssClass="GridFooter" />
                                <PagerStyle CssClass="GridPager" ForeColor="White" />
                                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                                <HeaderStyle CssClass="GridHeader"  />
                            </asp:GridView>

2 个答案:

答案 0 :(得分:7)

 <asp:BoundField ItemStyle-HorizontalAlign="Right" />

您也可以使用HeaderStyle-HorizontalAlign="Right"

OR

<RowStyle HorizontalAlign="Right" />

或者,创建一个text-align值为right的CSS类。然后,您可以将项目的CssClass属性设置为类。

答案 1 :(得分:7)

我相信你需要使用RowStyle:

<asp:GridView>
   <RowStyle HorizontalAlign="Right" />
</asp:GridView>

您可以在RowStyle here上找到更多详细信息。