Make of the Gridview Column Center and Right Align (MiddleRight)
Solution 1
How about aligning them to the right using
ItemStyle-HorizontalAlign="Right"
and then using CSS padding to add some space around the edge of the value in the cell?
Solution 2
Above accepted answer did not work for me. Although i did not try it in code as per above answer, i tried using the equivalent in the aspx page (which did not work).
<asp:BoundField etc>
<ItemStyle etc />
<HeaderStyle HorizontalAlign="Right" />
</asp:BoundField>
What worked for me was
<HeaderStyle CssClass="colHeader-RightAlign" />
and created a style within the <head>
<style type="text/css">
.colHeader-RightAlign {
text-align:right !important;
}
</style>
Solution 3
EDITED
This is what you need.
GridView1.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Right;
GridView1.Columns[0].ItemStyle.VerticalAlign = VerticalAlign.Middle;
This should work.
Solution 4
Try this for perticuler column alignment
protected void myGridView_RowDataBound(object o, GridViewRowEventArgs e)
{
// Set the alignment of cells containing numeric data.
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells[6].HorizontalAlign = HorizontalAlign.Right;
}
}
Krishna Thota
I'm a .Net Developer Working in Hyderabad. I have Knowledge on .NET, SQL Server, and other .Net Extensions
Updated on June 24, 2020Comments
-
Krishna Thota almost 4 years
I need to align the values inside the Grid View to to Center and Right. Because I need to align Currency.
And other Columns need to be aligned Center and Left.
Can you Help me doing This??
I'm currently Doing This.
<asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderText="Amount"> <ItemTemplate>Rs.<%# Eval("Payable_Bill_Amount","{0:n}")%></ItemTemplate> </asp:TemplateField>
This Aligns the Content to totally Right. I need to align the Content to Right But Also to Center Like Calculations We Do
Ex:
Required Current | 10.00 | | 10.00| | 110.00 | | 110.00| | 1210.00 | | 1210.00| ----------