Align the row values in a GridView

浪尽此生 提交于 2019-12-22 08:08:13

问题


I need to right align the values in a column of my gridview in asp.net 3.5 How can I do that?

                                <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>

回答1:


I believe you need to use the RowStyle:

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

You can find some more detail information on RowStyle here.




回答2:


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

You might also use HeaderStyle-HorizontalAlign="Right"

OR

<RowStyle HorizontalAlign="Right" />

Alternatively, create a CSS class with the text-align value to right. You can then set the CssClass property of the item to the class.



来源:https://stackoverflow.com/questions/3085687/align-the-row-values-in-a-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!