【问题标题】:Asp hyperlink alignmentasp超链接对齐
【发布时间】:2015-06-16 16:01:25
【问题描述】:

我希望超链接在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>

Horizo​​ntalAlign="Center" 不起作用,ItemStyle-Horizo​​ntalAlign="Center" 也不起作用。我已经按照here 的描述设置了样式,但这也不起作用。仅供参考,也涉及引导程序。我错过了什么?网格声明中的一些设置?请帮忙。

【问题讨论】:

    标签: asp.net gridview hyperlink center


    【解决方案1】:

    唯一可行的方法是在超链接周围放置一个 div,并在 div 中对齐。

                            <div style="text-align:center">
                         <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")))%>'/>
                        </div>
    

    【讨论】:

      【解决方案2】:

      这可以通过两种方法实现

      1- 尝试使用

      ' Font-Underline="false" NavigateUrl=''/>

                  </ItemTemplate>
      

      2- 或者你只是去查看你网页的源文件 尝试找到超链接的呈现 html ....然后将您的 在

      【讨论】:

        【解决方案3】:

        你可以用 css 做到这一点: 这是来自这篇文章的demopost

        你必须在表格单元格中添加一个 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;
            }
        

        【讨论】:

          【解决方案4】:

          在您的 CSS 文件中,编辑 td 标签的样式。

          td
          {
          text-align: center;
          }
          

          GridView 在网页上渲染时会转换为表格结构。所以 GridView 采用表格样式

          【讨论】:

          • 在这种情况下,可以编写一个 CSS 类以仅分配给该数据网格。但是我不确定是否需要为该特定单元格实现中心对齐 .datagrid td { text-align: center; }
          猜你喜欢
          • 1970-01-01
          • 2011-11-14
          • 2013-01-11
          • 1970-01-01
          • 1970-01-01
          • 2014-04-09
          • 1970-01-01
          • 1970-01-01
          • 2018-03-12
          相关资源
          最近更新 更多