c# - 如何在 asp :GridView 中使标题标题居中

标签 c# .net

有谁知道如何在 asp:GridView 中将标题居中?

例子:

enter image description here

我的代码如下:

<table border="0" width="500">
<tr>
    <td width="450px" align="center">
            <asp:GridView ID="grid" runat="server" AutoGenerateColumns="False"
              DataSourceID="dsTest" DataKeyNames="id"
              CellPadding="6" GridLines="None" AllowPaging="True" PageSize="20" AllowSorting="True" Width="450px">
              <Columns>
                <asp:TemplateField HeaderText="   Address" SortExpression="suburb, street">
                  <ItemTemplate>
                        <a style='cursor:pointer'  href='#'>
                     <%# Eval("unit_number") %> <%# Eval("level_number") %> <%# Eval("street_number") %> <%# Eval("street") %>
                     <%# Eval("suburb") %> <%# Eval("postcode") %></a>
                  </ItemTemplate>
                </asp:TemplateField>
              </Columns>
</asp:GridView>
</td>
</tr>
</table>

有谁知道我怎样才能将“地址”改为中心?我试图在 GridView 的 CSS 中设置文本对齐:“中心”,但它似乎对我不起作用

另外...如果我想在左侧显示更多地址,有人知道我该怎么做吗?

最佳答案

其实就是HeaderStyle-Horizo​​ntalAlign

<asp:TemplateField HeaderText="Address" SortExpression="suburb, street" HeaderStyle-HorizontalAlign="Center">

关于c# - 如何在 asp :GridView 中使标题标题居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5852453/

相关文章:

c# - 在 Asp Core 中上传时调整图像大小

.net - XMLArrayItem 的 XML 反序列化问题

c# - 如何在 C# 中连接到 .sdf 本地数据库文件

asp.net - HttpApplicationState.RemoveAll() 线程安全吗?

c# - 模型重建后如何保留自定义导航属性?

c# - 将屏幕坐标转换为复数坐标

c# - 通信协议(protocol)的单元测试

c# - 为什么 Entity Framework Core 2.2 C# 在使用现有嵌套实体插入新实体时会响应错误

c# - 运行时使用模拟的 Windows 服务帐户的 EF Code First 连接字符串

c# - 队列空值返回并抛出 NullReferenceException