【问题标题】:how to display more than one value in table?如何在表格中显示多个值?
【发布时间】:2015-09-10 12:02:33
【问题描述】:

我在 html 的基本表中显示来自数据库的值。

 <table>
    <tr>
           <td>
              <strong><label>CONTAINER NUMBERS</label></strong> <br />
              <asp:Label runat="server" ID="lblContainerNoMurphy"></asp:Label>
           </td>
    </tr>
    <tr> 
        <td>
          <strong><label>NO OF PIECES</label></strong> <br />
          <asp:Label runat="server" ID="lblNoOfPiecesMurphy"></asp:Label>
         </td>
     </tr>
</table>

我在这里从数据库中获取值:

    JobPiece piece = new JobPiece(Company.Current.CompanyID);
if (!string.IsNullOrEmpty(piece.ContainerNo))
     {
           lblContainerNoMurphy.Text = piece.ContainerNo;
     }

    if (!string.IsNullOrEmpty(piece.AdvisedQty))
     {
          lblNoOfPiecesMurphy.Text = piece.AdvisedQty;
    }

问题是一个作业有许多容器号和件数,但只有一个被显示。如何显示其他值?

【问题讨论】:

  • 标签将始终显示一个。您可以使用字符串构建器连接多个字符串或使用列表框(等)基本上任何内容来保存多个文本。或最好使用“Gridview”
  • 你能更好地解释一下“joab ha many container..”是什么吗?在您的代码中没有任何问题,显示了 ContainerNo 和 AdvidesQty 中的内容。如果您有 IEnumerable,则应使用数据网格或中继器并将它们绑定到数据源。
  • @Leonardo ContainerNo 和 AdvidesQty 在数据库中有很多行
  • @beginner91 很好,但您只要求 1 行与您的通话片段 = new JobPiece(...) 所以只会显示该值

标签: c# html asp.net visual-studio


【解决方案1】:

GridView是简单易用的控件。从数据库中获取值并填充数据表并将该数据表用作gridview 数据源。

GridView1.DataSource=YourDataSet.Tables[0];
GridView1.DataBind();

如果你想改变 gridview 的外观,你可以使用 CSS 轻松做到。

【讨论】:

    【解决方案2】:

    尝试像这样使用Repeater

    asp.net 代码

     <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <table>
                        <tr>
                            <td>
                                <strong><label>CONTAINER NUMBERS</label></strong><br />
                                <asp:Label runat="server"  Text='<%#Eval("name of the field to show from db ex: ContainerNo") %>' ID="lblContainerNoMurphy"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <strong><label>NO OF PIECES</label></strong><br />
                                <asp:Label runat="server" ID="lblNoOfPiecesMurphy" Text='<%#Eval("name of the field to show from db ex: AdvisedQty") %>' />
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:Repeater>
    

    C# 代码

    protected void Page_Load(object sender, EventArgs e)
        {
            List<JobPiece> items;    // get your items from database and put it in this list
    
            // fill repeater with your data
            Repeater1.DataSource = items;
            Repeater1.DataBind();
        }
    

    more information . more information

    【讨论】:

      猜你喜欢
      • 2013-07-20
      • 2018-08-27
      • 2017-12-27
      • 2018-04-02
      • 2019-04-06
      • 1970-01-01
      • 2015-04-30
      • 2017-12-22
      • 1970-01-01
      相关资源
      最近更新 更多