【问题标题】:Trying to underline the headertext in this gridview试图在此网格视图中为标题文本添加下划线
【发布时间】:2014-10-20 16:23:58
【问题描述】:

我正在尝试为整个标题文本添加下划线,使其看起来像下面的图片(标记为“试图使它看起来像”)。但它不会在整个标题文本中带有一致的下划线。谢谢你的帮助。

图片中写着:“试着让它看起来像”的部分是我希望它看起来像的样子 图片中“看起来像当前”的部分就是它当前的样子。

代码附在下面

  <asp:GridView runat="server" ID="grdvwDepositTransaction"
                AutoGenerateColumns="false" DataKeyNames="Status"
                OnRowCommand="grdvwDepositTransaction_RowCommand" ShowHeaderWhenEmpty="true" OnRowDataBound="grd_RowDataBound"
                CssClass="grid">

               <Columns>
                  <asp:TemplateField>
              <ItemTemplate>

              </ItemTemplate>
               </asp:TemplateField>

                  <asp:BoundField DataField="DepositEntry.cardNumber" HeaderText="Card Number" ItemStyle-CssClass="mediumColumn columnCenter" />
                  <asp:BoundField DataField="DepositEntry.accountNumber" HeaderText="Account Number" ItemStyle-CssClass="mediumColumn columnCenter" />
                  <asp:BoundField DataField="DepositEntry.firstName" HeaderText="Customer Name" ItemStyle-CssClass="mediumColumn columnCenter" />
                  <asp:BoundField DataField="DepositEntry.transactionDateTime" HeaderText="Transaction Date/Time" ItemStyle-CssClass="mediumColumn columnCenter" />
                  <asp:BoundField DataField="DepositEntry.cashAmount" HeaderText="Cash Amount" ItemStyle-CssClass="mediumColumn columnCenter" />
                  <asp:BoundField DataField="DepositEntry.depositAmount" HeaderText="Envelope Deposit Amount" ItemStyle-CssClass="mediumColumn columnCenter" />
               </Columns>
                    <EmptyDataTemplate>
                        <br />
                         <br /><br />
                        <span style="font-weight: bold; text-anchor:middle;">No Transactions have been entered</span>
                            </EmptyDataTemplate>                   
                           </asp:GridView>









  <table class="grid" cellspacing="0" rules="all" border="1"      id="MainContent_grdvwDepositTransaction" style="border-collapse:collapse;">
    <tr style="text-decoration:underline;">
        <th scope="col">&nbsp;</th><th scope="col">Card Number</th><th scope="col">Account Number</th><th scope="col">Customer Name</th><th scope="col">Transaction Date/Time</th><th scope="col">Cash Amount</th><th scope="col">Envelope Deposit Amount</th>
    </tr><tr>
        <td colspan="7">
                        <br />
                         <br />
                        <br />
                        <span style="font-weight: bold; text-anchor:middle;">No Transactions have been entered</span>
                    </td>
    </tr>
</table>


               <br />

                </div>

          </div>

【问题讨论】:

  • HTML 输出是什么样的?使用 CSS 应该很容易做到。
  • 这是我的想法!谢谢你看这个。 HTML 输出应该看起来像“看起来像当前图像”。
  • 这没有用,我需要查看实际的 HTML。
  • @DavidG 编辑了问题以包含 HTML 渲染参见灰色代码块。
  • 您可以使用 CSS 选择器选择表格的第一个 tr,并使用 border-bottom ,这实际上会在标题行下方添加一条连续线。

标签: c# css asp.net gridview


【解决方案1】:

此 CSS 将为具有 grid 类的 table 的第一个 tr 提供底部边框:

table.grid tr:first-of-type {
    border-bottom: 5px solid black;
}

【讨论】:

    【解决方案2】:

    我同意,你可以用 CSS 做到这一点。但是,如果您有兴趣从服务器端以编程方式执行此操作,我可以为您提供帮助。

    1. 如下定义 row_databound 事件。 OnRowDataBound="gvw_RowDataBound"
    2. 然后在服务器端,如果你找到header row

    接下来执行以下操作。

    • 创建一个额外的行,
    • 设置 colspan = 细胞计数
    • 添加所需的html,在这种情况下
    • 然后将额外的行附加到标题行。

    完整代码。

    protected void gvw_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridViewRow extraRow = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
            TableCell tc = new DataControlFieldCell(((DataControlFieldCell)e.Row.Cells[0]).ContainingField);
            tc.Text = "<hr/>";
            tc.ColumnSpan = e.Row.Cells.Count;
            extraRow.Cells.Add(tc);
            e.Row.Parent.Controls.AddAt(1, extraRow);
        }
    }
    

    来源 - http://forums.asp.net/p/1534978/3725419.aspx#3725419

    希望,这会有所帮助,以其他方式(以防有人想要添加任何自定义 html)!

    【讨论】:

      【解决方案3】:

      在您的列标签之前添加:

      <HeaderStyle CssClass="HeaderTemplate" />
      

      在您的 CSS 代码上,添加以下内容:

      .HeaderTemplate {
          border-bottom: 2px solid black;
      }
      

      【讨论】:

        猜你喜欢
        • 2012-02-21
        • 1970-01-01
        • 2015-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-07
        • 1970-01-01
        相关资源
        最近更新 更多