制作Gridview列中心并右对齐(MiddleRight)

时间:2012-09-11 07:34:18

标签: c# asp.net gridview alignment

我需要将网格视图中的值与中心和右边对齐。因为我需要对齐货币。

其他列需要与中心和左对齐。

你能帮我做这个吗?

我现在正在做这个。

<asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderText="Amount">
    <ItemTemplate>Rs.<%# Eval("Payable_Bill_Amount","{0:n}")%></ItemTemplate>
</asp:TemplateField>

这使内容完全正确。 我需要将内容与正确对齐,但也要像我们的计算中心那样

前:

 Required          Current

|    10.00  |   |     10.00|

|   110.00  |   |    110.00| 

|  1210.00  |   |   1210.00|
----------

5 个答案:

答案 0 :(得分:5)

如何使用

将它们对齐到右边
ItemStyle-HorizontalAlign="Right"

然后使用CSS填充在单元格中的值边缘周围添加一些空格?

答案 1 :(得分:3)

以上接受的答案对我不起作用。虽然我没有按照上面的答案在代码中尝试它,但我尝试在aspx页面中使用等效的(这不起作用)。

<asp:BoundField etc>
  <ItemStyle etc />
  <HeaderStyle HorizontalAlign="Right" />
</asp:BoundField>

对我有用的是

<HeaderStyle CssClass="colHeader-RightAlign" />

并在<head>

中创建了一个样式
<style type="text/css">
    .colHeader-RightAlign {
        text-align:right !important;
    }
</style>

答案 2 :(得分:1)

<强> EDITED

这就是你需要的。

 GridView1.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Right;
 GridView1.Columns[0].ItemStyle.VerticalAlign = VerticalAlign.Middle;

这应该有用。

答案 3 :(得分:1)

尝试使用perticuler列对齐

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

答案 4 :(得分:0)

 <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
 <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
相关问题