Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align the row values in a GridView

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>
like image 705
user279521 Avatar asked Jun 21 '10 14:06

user279521


2 Answers

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

like image 128
David Neale Avatar answered Nov 12 '22 00:11

David Neale


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.

like image 8
Abe Miessler Avatar answered Nov 11 '22 23:11

Abe Miessler