0

How can I center the text of the rows of an <asp:GridView /> that gets populated at run-time?

I have tried RowStyle-HorizontalAlign="Center" and similar things that I have found in this site to no avail.

Similarly, I cannot center a GridView inside a div—that is, <div><asp:GridView /></div>—to save my life.

Am I using a bunch of deprecated functions or what? Also, Chrome is my default browser.

I am aware that a thousand questions in the gist of mine have been asked before, but all that I have tried are either years old or are not working.

Thanks in advance!

4

1 回答 1

0

您是使用绑定列还是自动生成?如果你在你的标记中绑定它们,这样的事情应该可以正常工作(这是我的一个实际例子):

<asp:TemplateField HeaderText="External Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
    <EditItemTemplate>
        <asp:TextBox ID="txtExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
        <asp:TextBox ID="txtNewExternalId" runat="server" Width="100%" />
    </FooterTemplate>
    <ItemTemplate>
        <asp:Label ID="lblExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
于 2013-06-13T20:00:55.750 回答