我希望超链接在GridView的单元格中居中,这是网格列的代码:
<asp:TemplateField HeaderText="Ticket#" ItemStyle-HorizontalAlign="Center" SortExpression="ows_ID">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Hyperlink ID="hlID" Target="_parent" runat="server" Text='<%# Bind("ows_ID")%>' Font-Underline="false"
NavigateUrl='<%#"Default.aspx?TktNo=" & Server.UrlEncode(Trim(Container.DataItem("ows_ID")))%>'/>
</ItemTemplate>
</asp:TemplateField>HorizontalAlign="Center“不起作用,ItemStyle-HorizontalAlign="Center”也不起作用。我已经按照here的描述设置了样式,但这也不起作用。仅供参考,bootstrap也参与其中。我遗漏了什么?网格声明中的一些设置?请帮帮忙。
发布于 2015-04-11 04:37:29
在CSS文件中,编辑td标签的样式。
td
{
text-align: center;
}在网页上渲染时,GridView会转换为表格结构。所以GridView采用了表格的样式
发布于 2015-04-11 04:48:23
你可以用css:这是来自这篇文章的demo:post
你必须在表单元格中添加一个css类,并将你的css封装到这个类中,否则它会将所有的td对齐!
td {
height: 100%;
}
a {
display: table;
position: relative;
height: 100%;
width: 100%;
background-color: yellow;
}
span {
display: table-cell;
text-align:center;
vertical-align: middle;
background-color: red;
}发布于 2015-04-11 05:07:36
这可以通过两种方法来实现
1- 尝试使用
<中心>
‘Server.UrlEncode(Trim(Container.DataItem("ows_ID")))%>'/> =’<%#“Default.aspx?TktNo=”&false
</ItemTemplate>< /center >
2-或者您只是转到查看网页的源文件,尝试找到呈现的超链接....and的html,然后将< asp:Hyperlink >放在< span class="class1"> < /span >中
< .class1 >对齐{文本对齐:居中;}< /style >
https://stackoverflow.com/questions/29569819
复制相似问题