在Visual Studio 2010中对齐GridView

3

我知道这是非常基础的问题。我正在使用Visual Studio 2010创建一个网格。我想让网格居中对齐,而不是数据,它应该出现在页面的中间。有人可以告诉我如何做到吗?

3个回答

4

使用GridView的HorizontalAlign属性。

获取或设置页面上GridView控件的水平对齐方式。

<asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" >
</asp:GridView>

2

为你的网格视图设置宽度,然后将margin-left/right设置为auto。

示例:

<style type="text/css">
    .CenteredGrid { width:640px; margin-left:auto; margin-right:auto; }
    </style>

    <asp:GridView ID="GridView1" runat="server" CssClass="CenteredGrid">
     ... Codes ...
    </asp:GridView>

编辑:

这对页面上的任何控件/元素都适用。


2
创建一个居中对齐的 div,并将您的网格视图放置在其中。
   <div align="center">
    // put your gridview here
    </div>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接