【问题标题】:html table <td> width in repeater itemtemplate unable to set无法设置转发器项目模板中的 html 表 <td> 宽度
【发布时间】:2013-02-27 11:01:42
【问题描述】:

我正在尝试调整 HTML 表中作为 ASP 转发器项目持有者的列的宽度。

<asp:Repeater id="viewproduct" runat="server"> 
 <HeaderTemplate>
  <table id="grid">
    <thead >
       <tr>
         <th width="20px" data-field="check"></th>
         <th data-field="level">Status</th>
         <th data-field="Class">Username</th>
       </tr>
    </thead>
    <tbody>``
  </HeaderTemplate>
  <ItemTemplate>
      <tr>
      <td width="20px"><asp:CheckBox ID="CheckApprove" runat="server" Width="20px" /></td>                   
      <td><asp:Label ID="status" runat="server"
            Text='<%#DataBinder.Eval(Container.DataItem, "Status")%>'></asp:Label></td> 
      <td><asp:Label ID="name" runat="server"
            Text='<%#DataBinder.Eval(Container.DataItem, "name")%>'></asp:Label></td>
      </tr>
    </ItemTemplate>
  <FooterTemplate>
    </tbody>
    </table>
  </FooterTemplate>
</asp:Repeater>

请注意,标题跟随宽度,但内容不跟随。为什么? 这是我的桌子目前的样子:

【问题讨论】:

  • 为什么不用 CSS 来设置呢。
  • 您能向我们展示您生成的 HTML 的相关 sn-p 吗?
  • 从图像上看,似乎您没有向我们展示所有代码。看起来用户名右侧至少还有一列。我之所以提到这一点,是因为如果您的桌子上有更多内容,它可能会帮助我们找到问题。

标签: html asp.net html-table repeater


【解决方案1】:
Use style tag in th and td
<asp:Repeater id="viewproduct" runat="server"> 
 <HeaderTemplate>
  <table id="grid">
    <thead >
       <tr>
         <th style="width:20px;" data-field="check"></th>
         <th data-field="level">Status</th>
         <th data-field="Class">Username</th>
       </tr>
    </thead>
    <tbody>``
  </HeaderTemplate>
  <ItemTemplate>
      <tr>
      <td style="width:20px;" ><asp:CheckBox ID="CheckApprove" runat="server" Width="20px" /></td>                   
      <td><asp:Label ID="status" runat="server"
            Text='<%#DataBinder.Eval(Container.DataItem, "Status")%>'></asp:Label></td> 
      <td><asp:Label ID="name" runat="server"
            Text='<%#DataBinder.Eval(Container.DataItem, "name")%>'></asp:Label></td>
      </tr>
    </ItemTemplate>
  <FooterTemplate>
    </tbody>
    </table>
  </FooterTemplate>
</asp:Repeater>

【讨论】:

    【解决方案2】:

    style="width:20px;"代替width="20px"

    【讨论】:

      猜你喜欢
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2013-03-02
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 2016-12-14
      相关资源
      最近更新 更多